Searching in a Sorted Linked List and Sort Integers Into a Linked List

Total Page:16

File Type:pdf, Size:1020Kb

Searching in a Sorted Linked List and Sort Integers Into a Linked List SEARCHING IN A SORTED LINKED LIST AND SORT INTEGERS INTO A LINKED LIST A THESIS IN Computer Science Presented to the Faculty of the University of Missouri-Kansas City in partial fulfillment of the requirements for the degree MASTER OF SCIENCE By HEMASREE KOGANTI B. Tech(CS), GOKARAJU RANGARAJU INSTITUTE OF ENGINEERING AND TECHNOLOGY , India, 2015 Kansas City, Missouri 2019 ©2018 HEMASREE KOGANTI ALL RIGHTS RESERVED SEARCHING IN A SORTED LINKED LIST AND SORT INTEGERS INTO A LINKED LIST Hemasree Koganti, Candidate for the Master of Science Degree University of Missouri – Kansas City, 2018 ABSTRACT The research work consists of two parts. Part one is about Searching for an integer in a sorted Linked list. A tree is constructed in O(nloglogm/p+loglogm) time with p processors based on the trie with all the given integers. Additional nodes (O(nloglogm) of them) are added to the tree. After the tree is constructed, for any given integer we can find the predecessor and successor of the integer, insert or delete the integer in O(loglogm) time. The result demonstrates for the searching purpose we need not to sort the input numbers into a sorted array for this would need at least O(logn/loglogn) time while this algorithm for constructing the tree can run in O(loglogm) time with n processors. Part two is on sorting integers into a linked list. There are various best algorithms for sorting integers. The current research work applies the recent important results of sorting integers in (logn/loglogn) time. This algorithm takes “constant time” to sort integers into a linked list with nlogm processors and O(loglogm/logt) time using nt processors on the Priority CRCW PRAM model. iii APPROVAL PAGE The faculty listed below, appointed by the Dean of School of Computing and Engineering, have to examine the thesis titled “Searching in a Sorted Linked List and Sort Integers into a Linked List” presented by Hemasree Koganti, candidate for the Master of Science degree, and certify that in their opinion it is worthy of acceptance. Supervisory Committee Yijie Han, Ph.D., Chair School of Computing and Engineering Ken Mitchell, Ph.D. Department of Computer Science Electrical Engineering Sejun Song, Ph.D. Department of Computer Science Electrical Engineering iv CONTENTS ABSTRACT ................................................................................................................................... iii ILLUSTRATIONS ......................................................................................................................... vi ACKNOWLEDGEMENTS ........................................................................................................... vii CHAPTER 1. INTRODUCTION ............................................................................................................. 1 2. SEARCHING IN A SORTED LINKED LIST ................................................................. 4 2.1 Introduction ................................................................................................................. 4 2.2 Building the Search Tree based on a Trie .................................................................... 5 2.3 Augmenting the Tree ................................................................................................... 8 2.4 Searching ..................................................................................................................... 9 3. SORT INTEGERS INTO A LINKED LIST .................................................................... 11 3.1 Introduction ................................................................................................................ 11 3.2 The Algorithm .......................................................................................................... 12 3.3 Building a Tree Based on a Trie: An Example ......................................................... 19 4. CONCLUSION ............................................................................................................... 23 REFERENCES .................................................................................................................... 25 VITA .............................................................................................................................................. 28 v ILLUSTRATIONS Figure Page 1. Example of a Trie……………………………………………………………………5 2. Trie with Step numbers ……………………………………………………………………...6 3. Final Trie…………………...………………………………………………………..10 4. Processors assigned to each Input Integer…………………………………………...12 5. Example of a Trie…………………………………………........................................13 6. The Nodes with one child are removed……………………………………………...14 7. All the Nodes are shown……………………………………………………………..15 8. Trie with ‘a’ sections………………….……………………………………………..19 9. Intermediate Levels are removed…………………………………………………….20 10. Linked Lists are formed at the Nodes………………………………………………..21 11. Parent Node connects all its child Linked Lists……………………………………...22 vi ACKNOWLEDGEMENTS I would like to take this opportunity to thank following people who have directly or indirectly helped me in academic achievements. Firstly, I would like to thank Dr. Yijie Han for the constant and endearing support which has helped me in fulfilling my thesis. He has provided me with an opportunity to realize my potential in the field of my thesis. His encouragement and inputs were elements of vital guidance in my thesis. He has been a constant source of motivation and challenged me with algorithms, deadlines, that have contributed to me acquiring inspiration and ideology. His expertise and innovative insights have been phenomenal in completing my thesis. I sincerely thank Dr. Ken Mitchell and Dr. Sejun Song for accepting to be a part of my thesis committee and making time for me from their busy schedule. I would like to thank the University of Missouri- Kansas City for providing me with an opportunity to continue my research and supporting me in this regard. I would like to dedicate my thesis to my parents who constantly inspired me to pursue higher studies. I would like to thank my family who stood behind me all these years during my degree. Finally, I would like to thank all my teachers, educational administrators, present, and past and all who helped me achieve this academic goal. vii CHAPTER 1 INTRODUCTION In computer science, algorithms play a crucial role. Time and space complexities are major concern in terms of CPU and memory usage, performance and efficiency. The performance of the developed system is determined by the efficient algorithm used by it. There are various algorithms available for various purposes. It is well know that n objects drawn from an arbitrary totally ordered universe can be sorted by n processors in O(log n) time, even given a very weak model of parallel computation such as the processor network of bounded degree (assuming, of course, that binary comparisons take unit time). This result is optimal in the sense that the product of the number of processors and the time used is O(n log n), to be compared with a lower time bound of Ω(n log n) for any sequential algorithm operating according to the decision-tree model. Reif obtained a partial solution by giving a probabilistic algorithm that sorts n integers in the range {1, . n}, uses O(n/logn) processors, and terminates within O(log n) steps with high probability. Some doubt remains as to whether his algorithm is able to sort larger numbers, the question hinging on whether the sorting can be made stable. We investigate the restricted sorting problem in a deterministic setting. The algorithms we have developed has overcome the memory usage and performance issues. To achieve this I have used the recent best results of Parallel binary search with delayed read conflicts [10] by H.Meijer and S.G.Akl where search can be done in O(logn/logw) time where w is the number of bits in a word. The computation model used in both the paper’s is the CRCW (Concurrent Read Concurrent Write) PRAM (Parallel Random-Access Machine) Model. On the CRCW PRAM memory is shared among processors and multiple processors 1 can read the same memory cell in one step and can write to the same memory cell in one step. When concurrent write happens, we use the Priority CRCW PRAM in which when multiple processors write the same cell in one step the highest indexed processor wins the write. In the part one, we are going to construct a search tree for the sorted n input integers using a trie. Such a tree can be constructed in O(nloglogm/p+loglogm) time for n integers in {0, 1, …, m-1} using p processors on the CRCW (Concurrent Read Concurrent Write) PRAM (Parallel Random-Access Machine) [8]. We will add O(loglogm) nodes for each node in the tree to facilitate searching. After the tree is built then searching among these n input integers can be done in O(loglogm) time. The technique presented in this paper has been used to achieve an O(n/p+loglogloglogm) time CRCW PRAM merging algorithm [7]. This has been published as a research paper to “International Conference on Information Technology 2018, Bhubaneshwar, India”. The paper was accepted to the conference with Paper Id 2. In Algorithm 2, we show that n integers in {0, 1, …, m-1} can be sorted into a linked list in constant time using nlogm processors on the Priority CRCW PRAM model, and they can be sorted into a linked list in O(loglogm/logt) time using nt processors on the Priority CRCW PRAM model. We use a trie of height logm to sort integers into a linked list. We use A[i][j] to represent
Recommended publications
  • Application of TRIE Data Structure and Corresponding Associative Algorithms for Process Optimization in GRID Environment
    Application of TRIE data structure and corresponding associative algorithms for process optimization in GRID environment V. V. Kashanskya, I. L. Kaftannikovb South Ural State University (National Research University), 76, Lenin prospekt, Chelyabinsk, 454080, Russia E-mail: a [email protected], b [email protected] Growing interest around different BOINC powered projects made volunteer GRID model widely used last years, arranging lots of computational resources in different environments. There are many revealed problems of Big Data and horizontally scalable multiuser systems. This paper provides an analysis of TRIE data structure and possibilities of its application in contemporary volunteer GRID networks, including routing (L3 OSI) and spe- cialized key-value storage engine (L7 OSI). The main goal is to show how TRIE mechanisms can influence de- livery process of the corresponding GRID environment resources and services at different layers of networking abstraction. The relevance of the optimization topic is ensured by the fact that with increasing data flow intensi- ty, the latency of the various linear algorithm based subsystems as well increases. This leads to the general ef- fects, such as unacceptably high transmission time and processing instability. Logically paper can be divided into three parts with summary. The first part provides definition of TRIE and asymptotic estimates of corresponding algorithms (searching, deletion, insertion). The second part is devoted to the problem of routing time reduction by applying TRIE data structure. In particular, we analyze Cisco IOS switching services based on Bitwise TRIE and 256 way TRIE data structures. The third part contains general BOINC architecture review and recommenda- tions for highly-loaded projects.
    [Show full text]
  • CS 106X, Lecture 21 Tries; Graphs
    CS 106X, Lecture 21 Tries; Graphs reading: Programming Abstractions in C++, Chapter 18 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution 2.5 License. All rights reserved. Based on slides created by Keith Schwarz, Julie Zelenski, Jerry Cain, Eric Roberts, Mehran Sahami, Stuart Reges, Cynthia Lee, Marty Stepp, Ashley Taylor and others. Plan For Today • Tries • Announcements • Graphs • Implementing a Graph • Representing Data with Graphs 2 Plan For Today • Tries • Announcements • Graphs • Implementing a Graph • Representing Data with Graphs 3 The Lexicon • Lexicons are good for storing words – contains – containsPrefix – add 4 The Lexicon root the art we all arts you artsy 5 The Lexicon root the contains? art we containsPrefix? add? all arts you artsy 6 The Lexicon S T A R T L I N G S T A R T 7 The Lexicon • We want to model a set of words as a tree of some kind • The tree should be sorted in some way for efficient lookup • The tree should take advantage of words containing each other to save space and time 8 Tries trie ("try"): A tree structure optimized for "prefix" searches struct TrieNode { bool isWord; TrieNode* children[26]; // depends on the alphabet }; 9 Tries isWord: false a b c d e … “” isWord: true a b c d e … “a” isWord: false a b c d e … “ac” isWord: true a b c d e … “ace” 10 Reading Words Yellow = word in the trie A E H S / A E H S A E H S A E H S / / / / / / / / A E H S A E H S A E H S A E H S / / / / / / / / / / / / A E H S A E H S A E H S / / / / / / /
    [Show full text]
  • Introduction to Linked List: Review
    Introduction to Linked List: Review Source: http://www.geeksforgeeks.org/data-structures/linked-list/ Linked List • Fundamental data structures in C • Like arrays, linked list is a linear data structure • Unlike arrays, linked list elements are not stored at contiguous location, the elements are linked using pointers Array vs Linked List Why Linked List-1 • Advantages over arrays • Dynamic size • Ease of insertion or deletion • Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to be shifted For example, in a system if we maintain a sorted list of IDs in an array id[]. id[] = [1000, 1010, 1050, 2000, 2040] If we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 • Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in id[], everything after 1010 has to be moved Why Linked List-2 • Drawbacks of Linked List • Random access is not allowed. • Need to access elements sequentially starting from the first node. So we cannot do binary search with linked lists • Extra memory space for a pointer is required with each element of the list Representation in C • A linked list is represented by a pointer to the first node of the linked list • The first node is called head • If the linked list is empty, then the value of head is null • Each node in a list consists of at least two parts 1.
    [Show full text]
  • University of Cape Town Declaration
    The copyright of this thesis vests in the author. No quotation from it or information derived from it is to be published without full acknowledgementTown of the source. The thesis is to be used for private study or non- commercial research purposes only. Cape Published by the University ofof Cape Town (UCT) in terms of the non-exclusive license granted to UCT by the author. University Automated Gateware Discovery Using Open Firmware Shanly Rajan Supervisor: Prof. M.R. Inggs Co-supervisor: Dr M. Welz University of Cape Town Declaration I understand the meaning of plagiarism and declare that all work in the dissertation, save for that which is properly acknowledged, is my own. It is being submitted for the degree of Master of Science in Engineering in the University of Cape Town. It has not been submitted before for any degree or examination in any other university. Signature of Author . Cape Town South Africa May 12, 2013 University of Cape Town i Abstract This dissertation describes the design and implementation of a mechanism that automates gateware1 device detection for reconfigurable hardware. The research facilitates the pro- cess of identifying and operating on gateware images by extending the existing infrastruc- ture of probing devices in traditional software by using the chosen technology. An automated gateware detection mechanism was devised in an effort to build a software system with the goal to improve performance and reduce software development time spent on operating gateware pieces by reusing existing device drivers in the framework of the chosen technology. This dissertation first investigates the system design to see how each of the user specifica- tions set for the KAT (Karoo Array Telescope) project in [28] could be achieved in terms of design decisions, toolchain selection and software modifications.
    [Show full text]
  • Linux Kernel and Driver Development Training Slides
    Linux Kernel and Driver Development Training Linux Kernel and Driver Development Training © Copyright 2004-2021, Bootlin. Creative Commons BY-SA 3.0 license. Latest update: October 9, 2021. Document updates and sources: https://bootlin.com/doc/training/linux-kernel Corrections, suggestions, contributions and translations are welcome! embedded Linux and kernel engineering Send them to [email protected] - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/470 Rights to copy © Copyright 2004-2021, Bootlin License: Creative Commons Attribution - Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0/legalcode You are free: I to copy, distribute, display, and perform the work I to make derivative works I to make commercial use of the work Under the following conditions: I Attribution. You must give the original author credit. I Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. I For any reuse or distribution, you must make clear to others the license terms of this work. I Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. Document sources: https://github.com/bootlin/training-materials/ - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/470 Hyperlinks in the document There are many hyperlinks in the document I Regular hyperlinks: https://kernel.org/ I Kernel documentation links: dev-tools/kasan I Links to kernel source files and directories: drivers/input/ include/linux/fb.h I Links to the declarations, definitions and instances of kernel symbols (functions, types, data, structures): platform_get_irq() GFP_KERNEL struct file_operations - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/470 Company at a glance I Engineering company created in 2004, named ”Free Electrons” until Feb.
    [Show full text]
  • Implementing the Map ADT Outline
    Implementing the Map ADT Outline ´ The Map ADT ´ Implementation with Java Generics ´ A Hash Function ´ translation of a string key into an integer ´ Consider a few strategies for implementing a hash table ´ linear probing ´ quadratic probing ´ separate chaining hashing ´ OrderedMap using a binary search tree The Map ADT ´A Map models a searchable collection of key-value mappings ´A key is said to be “mapped” to a value ´Also known as: dictionary, associative array ´Main operations: insert, find, and delete Applications ´ Store large collections with fast operations ´ For a long time, Java only had Vector (think ArrayList), Stack, and Hashmap (now there are about 67) ´ Support certain algorithms ´ for example, probabilistic text generation in 127B ´ Store certain associations in meaningful ways ´ For example, to store connected rooms in Hunt the Wumpus in 335 The Map ADT ´A value is "mapped" to a unique key ´Need a key and a value to insert new mappings ´Only need the key to find mappings ´Only need the key to remove mappings 5 Key and Value ´With Java generics, you need to specify ´ the type of key ´ the type of value ´Here the key type is String and the value type is BankAccount Map<String, BankAccount> accounts = new HashMap<String, BankAccount>(); 6 put(key, value) get(key) ´Add new mappings (a key mapped to a value): Map<String, BankAccount> accounts = new TreeMap<String, BankAccount>(); accounts.put("M",); accounts.put("G", new BankAcnew BankAccount("Michel", 111.11)count("Georgie", 222.22)); accounts.put("R", new BankAccount("Daniel",
    [Show full text]
  • Algorithms & Data Structures: Questions and Answers: May 2006
    Algorithms & Data Structures: Questions and Answers: May 2006 1. (a) Explain how to merge two sorted arrays a1 and a2 into a third array a3, using diagrams to illustrate your answer. What is the time complexity of the array merge algorithm? (Note that you are not asked to write down the array merge algorithm itself.) [Notes] First compare the leftmost elements in a1 and a2, and copy the lesser element into a3. Repeat, ignoring already-copied elements, until all elements in either a1 or a2 have been copied. Finally, copy all remaining elements from either a1 or a2 into a3. Loop invariant: left1 … i–1 i … right1 a1 already copied still to be copied left2 … j–1 j … right2 a2 left left+1 … k–1 k … right–1 right a3 already copied unoccupied Time complexity is O(n), in terms of copies or comparisons, where n is the total length of a1 and a2. (6) (b) Write down the array merge-sort algorithm. Use diagrams to show how this algorithm works. What is its time complexity? [Notes] To sort a[left…right]: 1. If left < right: 1.1. Let mid be an integer about midway between left and right. 1.2. Sort a[left…mid]. 1.3. Sort a[mid+1…right]. 1.4. Merge a[left…mid] and a[mid+1…right] into an auxiliary array b. 1.5. Copy b into a[left…right]. 2. Terminate. Invariants: left mid right After step 1.1: a unsorted After step 1.2: a sorted unsorted After step 1.3: a sorted sorted After step 1.5: a sorted Time complexity is O(n log n), in terms of comparisons.
    [Show full text]
  • Foundations of Differentially Oblivious Algorithms
    Foundations of Differentially Oblivious Algorithms T-H. Hubert Chan Kai-Min Chung Bruce Maggs Elaine Shi August 5, 2020 Abstract It is well-known that a program's memory access pattern can leak information about its input. To thwart such leakage, most existing works adopt the technique of oblivious RAM (ORAM) simulation. Such an obliviousness notion has stimulated much debate. Although ORAM techniques have significantly improved over the past few years, the concrete overheads are arguably still undesirable for real-world systems | part of this overhead is in fact inherent due to a well-known logarithmic ORAM lower bound by Goldreich and Ostrovsky. To make matters worse, when the program's runtime or output length depend on secret inputs, it may be necessary to perform worst-case padding to achieve full obliviousness and thus incur possibly super-linear overheads. Inspired by the elegant notion of differential privacy, we initiate the study of a new notion of access pattern privacy, which we call \(, δ)-differential obliviousness". We separate the notion of (, δ)-differential obliviousness from classical obliviousness by considering several fundamental algorithmic abstractions including sorting small-length keys, merging two sorted lists, and range query data structures (akin to binary search trees). We show that by adopting differential obliv- iousness with reasonable choices of and δ, not only can one circumvent several impossibilities pertaining to full obliviousness, one can also, in several cases, obtain meaningful privacy with little overhead relative to the non-private baselines (i.e., having privacy \almost for free"). On the other hand, we show that for very demanding choices of and δ, the same lower bounds for oblivious algorithms would be preserved for (, δ)-differential obliviousness.
    [Show full text]
  • Highly Parallel Fast KD-Tree Construction for Interactive Ray Tracing of Dynamic Scenes
    EUROGRAPHICS 2007 / D. Cohen-Or and P. Slavík Volume 26 (2007), Number 3 (Guest Editors) Highly Parallel Fast KD-tree Construction for Interactive Ray Tracing of Dynamic Scenes Maxim Shevtsov, Alexei Soupikov and Alexander Kapustin† Intel Corporation Figure 1: Dynamic scenes ray traced using parallel fast construction of kd-tree. The scenes were rendered with shadows, 1 TM reflection (except HAND) and textures at 512x512 resolution on a 2-way Intel °R Core 2 Duo machine. a) HAND - a static model of a man with a dynamic hand; 47K static and 8K dynamic triangles; 2 lights; 46.5 FPS. b) GOBLIN - a static model of a hall with a dynamic model of a goblin; 297K static and 153K dynamic triangles; 2 lights; 9.2 FPS. c) BAR - a static model of bar Carta Blanca with a dynamic model of a man; 239K static and 53K dynamic triangles; 2 lights; 12.6 FPS. d) OPERA TEAM - a static model of an opera house with a dynamic model of 21 men without instancing; 78K static and 1105K dynamic triangles; 4 lights; 2.0 FPS. Abstract We present a highly parallel, linearly scalable technique of kd-tree construction for ray tracing of dynamic ge- ometry. We use conventional kd-tree compatible with the high performing algorithms such as MLRTA or frustum tracing. Proposed technique offers exceptional construction speed maintaining reasonable kd-tree quality for ren- dering stage. The algorithm builds a kd-tree from scratch each frame, thus prior knowledge of motion/deformation or motion constraints are not required. We achieve nearly real-time performance of 7-12 FPS for models with 200K of dynamic triangles at 1024x1024 resolution with shadows and textures.
    [Show full text]
  • Lecture 8.Key
    CSC 391/691: GPU Programming Fall 2015 Parallel Sorting Algorithms Copyright © 2015 Samuel S. Cho Sorting Algorithms Review 2 • Bubble Sort: O(n ) 2 • Insertion Sort: O(n ) • Quick Sort: O(n log n) • Heap Sort: O(n log n) • Merge Sort: O(n log n) • The best we can expect from a sequential sorting algorithm using p processors (if distributed evenly among the n elements to be sorted) is O(n log n) / p ~ O(log n). Compare and Exchange Sorting Algorithms • Form the basis of several, if not most, classical sequential sorting algorithms. • Two numbers, say A and B, are compared between P0 and P1. P0 P1 A B MIN MAX Bubble Sort • Generic example of a “bad” sorting 0 1 2 3 4 5 algorithm. start: 1 3 8 0 6 5 0 1 2 3 4 5 Algorithm: • after pass 1: 1 3 0 6 5 8 • Compare neighboring elements. • Swap if neighbor is out of order. 0 1 2 3 4 5 • Two nested loops. after pass 2: 1 0 3 5 6 8 • Stop when a whole pass 0 1 2 3 4 5 completes without any swaps. after pass 3: 0 1 3 5 6 8 0 1 2 3 4 5 • Performance: 2 after pass 4: 0 1 3 5 6 8 Worst: O(n ) • 2 • Average: O(n ) fin. • Best: O(n) "The bubble sort seems to have nothing to recommend it, except a catchy name and the fact that it leads to some interesting theoretical problems." - Donald Knuth, The Art of Computer Programming Odd-Even Transposition Sort (also Brick Sort) • Simple sorting algorithm that was introduced in 1972 by Nico Habermann who originally developed it for parallel architectures (“Parallel Neighbor-Sort”).
    [Show full text]
  • Singly-Linked Listslists
    Singly-LinkedSingly-Linked ListsLists © 2011 John Wiley & Sons, Data Structures and Algorithms Using Python, by Rance D. Necaise. Modifications by Nathan Sprague LinkedLinked StructureStructure Constructed using a collection of objects called nodes. Each node contains data and at least one reference or link to another node. Linked list – a linked structure in which the nodes are linked together in linear order. © 2011 John Wiley & Sons, Data Structures and Algorithms Using Python, by Rance D. Necaise. Linked Structures – 2 LinkedLinked ListList Terms: head – first node in the list. tail – last node in the list; link field has a null reference. self._ © 2011 John Wiley & Sons, Data Structures and Algorithms Using Python, by Rance D. Necaise. Linked Structures – 3 LinkedLinked ListList Most nodes have no name; they are referenced via the link of the preceding node. head reference – the first node must be named or referenced by an external variable. Provides an entry point into the linked list. An empty list is indicated by a null head reference. self._ © 2011 John Wiley & Sons, Data Structures and Algorithms Using Python, by Rance D. Necaise. Linked Structures – 4 SinglySingly LinkedLinked ListList A linked list in which each node contains a single link field and allows for a complete linear order traversal from front to back. self._ © 2011 John Wiley & Sons, Data Structures and Algorithms Using Python, by Rance D. Necaise. Linked Structures – 5 NodeNode DefinitionDefinition The nodes are constructed from a simple storage class: class ListNode: def __init__(self, data, next_node): self.data = data self.next = next_node © 2011 John Wiley & Sons, Data Structures and Algorithms Using Python, by Rance D.
    [Show full text]
  • Sorting Algorithm 1 Sorting Algorithm
    Sorting algorithm 1 Sorting algorithm In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) that require sorted lists to work correctly; it is also often useful for canonicalizing data and for producing human-readable output. More formally, the output must satisfy two conditions: 1. The output is in nondecreasing order (each element is no smaller than the previous element according to the desired total order); 2. The output is a permutation, or reordering, of the input. Since the dawn of computing, the sorting problem has attracted a great deal of research, perhaps due to the complexity of solving it efficiently despite its simple, familiar statement. For example, bubble sort was analyzed as early as 1956.[1] Although many consider it a solved problem, useful new sorting algorithms are still being invented (for example, library sort was first published in 2004). Sorting algorithms are prevalent in introductory computer science classes, where the abundance of algorithms for the problem provides a gentle introduction to a variety of core algorithm concepts, such as big O notation, divide and conquer algorithms, data structures, randomized algorithms, best, worst and average case analysis, time-space tradeoffs, and lower bounds. Classification Sorting algorithms used in computer science are often classified by: • Computational complexity (worst, average and best behaviour) of element comparisons in terms of the size of the list . For typical sorting algorithms good behavior is and bad behavior is .
    [Show full text]