A Taxonomy of Parallel Sorting

Total Page:16

File Type:pdf, Size:1020Kb

A Taxonomy of Parallel Sorting A Taxonomy of Parallel Sorting DINA BITTON Department of Applied Mathematics, We~zmannInstitute, Rehovot, Israel DAVID J. DeWITT Computer Science Department, Unwerstty o[ Wisconsin, Madison, Wisconsin 53706 DAVID K. HSIAO AND JAISHANKAR MENON Computer and Information Science Department, The Ohio State University, Columbus, Ohio 43210 We propose a taxonomy of parallel sorting that encompasses a broad range of array- and file-sorting algorithms. We analyze how research on parallel sorting has evolved, from the earliest sorting networks to shared memory algorithms and VLSI sorters. In the context of sorting networks, we describe two fundamental parallel merging schemes: the odd-even and the bitonic merge. We discuss sorting algorithms that evolved from these merging schemes for parallel computers, whose processors communicate through interconnection networks such as the perfect shuffle, the mesh, and a number of other sparse networks. Following our discussion of network sorting algorithms, we describe how faster algorithms have been derived from parallel enumeration sorting schemes, where, with a shared memory model of parallel computation, keys are first ranked and then rearranged according to their rank. Parallel sorting algorithms are evaluated according to several criteria related to both the time complexity of an algorithm and its feasibility from the viewpoint of computer architecture. We show that, in addition to attractive communication schemes, network sorting algorithms have nonadaptive schedules that make them suitable for implementation. In particular, they are easily generalized to block sorting algorithms, which utilize limited parallelism to solve large sorting problems. We also address the problem of sorting large mass-storage files in parallel, using modified disk devices or intelligent bubble memory. We conclude by mentioning VLSI sorting as an active and promising direction for research on parallel sorting. Categories and Subject Descriptors: B.3 [Hardware]: Memory Structures; B.4 [Hardware]: Input/Output and Data Communications; B.7.1 [Integrated Circuits]: Types and Design Styles; F.2.2 [Analysis of Algorithms and Problem Complexity]: Nonnumerical Algorithms and Problems General Terms: Algorithms Additional Key Words and Phrases: Block sorting, bubble memory, external sorting, hardware sorters, internal sorting, limited parallelism, merging, parallel sorting, sorting networks D. Bitton's present address is Department of Computer Science, Cornell University, Ithaca, New York 14853. Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. © 1984 ACM 0360-0300/84/0900-0287 $00.75 Computing Surveys, Vol. 16, No. 3, September 1984 288 • D. Bitton, D. J. De Witt, D. K. Hsiao, and J. Menon CONTENTS efficient serial algorithms are known which can sort n values in at most O(n log n) comparisons, the theoretic lower bound for this problem [Knuth 1973]. In addition to INTRODUCTION their time complexity, various other prop- 1 PARALLELIZING SERIAL SORTING erties of these serial internal sorting algo- ALGORITHMS rithms have also been investigated. In 1 1 The Odd-Even Transposition Sort particular, sorting algorithms have been 1 2 A Parallel Tree-Sort Algorithm 2 NETWORK SORTING ALGORITHMS evaluated with respect to time-memory 2 1 Sorting Networks trade-offs (the amount of additional memory 2 2 Sorting on an SIMD Machine required to run the algorithm in addition 2.3 Summary to the memory storing the initial sequence), 3. SHARED MEMORY PARALLEL SORTING ALGORITHMS stability (the requirement that equal ele- 3.1 A Modified Sorting Network ments retain their original relative order), 3 2 Faster Parallel Merging Algorithms and sensitivity to the initial distribution of 3 3 Bucket Sorting the values (in particular, best case and 3 4 Sorting by Enumeration worst case complexity have been investi- 3 5 Summary 4 BLOCK SORTING ALGORITHMS gated). 41 Two-Way Merge-Spht In the last decade, parallel processing has 4 2 Bltonic Merge-Exchange added a new dimension to research on in- 5. EXTERNAL SORTING ALGORITHMS ternal sorting algorithms. Several models 5.1 Parallel Tape Sorting 5.2 Parallel Disk Sorting of parallel computation have been consid- 5.3 Analysis of the Parallel External ered, each with its own idea of "contiguous" Sorting Algorithm memory locations and definition of the way 6 HARDWARE SORTERS multiple processors access memory. In or- 61 The Rebound Sorter der to state the problem of parallel sorting 6 2 The Up-Down Sorter 6 3 Sorting within Bubble Memory clearly, we must first define what is meant 6 4 Summary and Recent Results by a sorted sequence in a parallel processor. 7 CONCLUSIONS AND OPEN PROBLEMS When processors share a common memory, REFERENCES the idea of contiguous memory locations in a parallel processor is identical to that in a A v serial processor. Thus, as in the serial case, the time complexity of a sorting algorithm INTRODUCTION can be expressed in terms of number of comparisons (performed in parallel by all Sorting in computer terminology is defined or some of the processors) and internal as the process of rearranging a sequence of memory moves. On the other hand, when values in ascending or descending order. processors do not share memory and com- Computer programs such as compilers or municate along the lines of an interconnec- editors often'choose to sort tables and lists tion network, definition of the sorting prob- of symbols stored in memory in order to lem requires a convention to order the enhance the speed and simplicity of algo- processors and thus the union of their rithms used to access them (for the search local memory locations. When parallel pro- or insertion of additional elements, for in- cessors are used, the time complexity of a stance). Because of both their practical im- sorting algorithm is expressed in terms of portance and theoretical interest, algo- parallel comparisons and exchanges be- rithms for sorting values stored in random tween processors that are adjacent in the access memory (internal sorting) have been interconnecting network. the focus of extensive research on algo- Shared memory models of parallel com- rithms. First, serial sorting algorithms were putation have been instrumental in inves- investigated. Then, with the advent of par- tigating the intrinsic parallelism that exists allel processing, parallel sorting algorithms in the sorting problem. Whereas the first became a very active area of research. Many results on parallel sorting were related to Computing Surveys, Voi. 16, No. 3, September 1984 A Taxonomy o/Parallel Sorting • 289 sorting networks [Batcher 1968], faster in research on new external sorting parallel sorting algorithms have been pro- schemes. The reasons for the relatively posed for theoretical models of parallel small amount of research on parallel exter- processors with shared memory [Hirsch- nal sorting [Bitton-Friedland 1982; Even berg 1978; Preparata 1978]. A chain of re- 1974] are most likely related to the neces- sults in shared memory computation has sity of adapting such schemes to mass- led to a number of parallel sorting schemes storage device characteristics. that exhibit a O(log n) time complexity. It may seem that advances in computer Typically, the parallel sorting problem is technology, such as the advent of intelli- expressed as that of sorting n numbers with gent or associative memories, could elimi- n or more processors, all sharing a large nate or reduce the use of sorting as a tool common memory, so that they may access for performing other operations. For ex- with various degrees of contention (e.g., ample, when sorting is used in order to parallel reads and parallel writes with ar- facilitate searching, one may advocate that bitration). Research on paralle ! sorting has associative memories will suppress the need been largely concerned with purely theoret- of sorting. However, associative stores re- ical issues, and it is only recently that fea- main too expensive for widespread use, es- sibility issues such as limited parallelism pecially when large volumes of data are or, in the context of very large scale inte- involved. In the case where sorting is re- gration (VLSI) sorting, trade-offs between quired for the sole purpose of ordering data, hardware complexity (expressed in terms the only way to reduce sorting time is to of chip area) and time complexity are being develop fast parallel sorting schemes, pos- addressed. sibly by integrating sorting capability into In addition to using sorting algorithms mass-storage memory [Chen et al. 1978; to rearrange numbers in memory, sorting Chung et al. 1980]. is often advocated in the context of infor- In this paper, we propose a taxonomy of mation processing. In this context, sorting parallel sorting that includes both internal is used to order a file of data records, stored and external parallel sorting algorithms. on a mass-storage device. The records are We analyze how research on parallel sort- ordered with respect to the value of a key, ing has evolved from the earliest sorting which might be a single field or the con- networks to shared memory model algo- catenation of several fields in the record. rithms and VLSI sorters. We attempt to Files are sorted either to deliver well-orga- classify a broad range of parallel sorting nized output to a user (e.g., a telephone algorithms according to various criteria, in- directory), or as an intermediate step in the cluding time efficiency and the architec- execution of a complex database operation tural requirements upon which they de- [Bitton and DeWitt 1983; Selinger et al. pend. The goal of this study is to provide a 1979]. Because of memory limitations file basic understanding and a unified view of sorting cannot be performed in memory the body of research on parallel sorting.
Recommended publications
  • Sort Algorithms 15-110 - Friday 2/28 Learning Objectives
    Sort Algorithms 15-110 - Friday 2/28 Learning Objectives • Recognize how different sorting algorithms implement the same process with different algorithms • Recognize the general algorithm and trace code for three algorithms: selection sort, insertion sort, and merge sort • Compute the Big-O runtimes of selection sort, insertion sort, and merge sort 2 Search Algorithms Benefit from Sorting We use search algorithms a lot in computer science. Just think of how many times a day you use Google, or search for a file on your computer. We've determined that search algorithms work better when the items they search over are sorted. Can we write an algorithm to sort items efficiently? Note: Python already has built-in sorting functions (sorted(lst) is non-destructive, lst.sort() is destructive). This lecture is about a few different algorithmic approaches for sorting. 3 Many Ways of Sorting There are a ton of algorithms that we can use to sort a list. We'll use https://visualgo.net/bn/sorting to visualize some of these algorithms. Today, we'll specifically discuss three different sorting algorithms: selection sort, insertion sort, and merge sort. All three do the same action (sorting), but use different algorithms to accomplish it. 4 Selection Sort 5 Selection Sort Sorts From Smallest to Largest The core idea of selection sort is that you sort from smallest to largest. 1. Start with none of the list sorted 2. Repeat the following steps until the whole list is sorted: a) Search the unsorted part of the list to find the smallest element b) Swap the found element with the first unsorted element c) Increment the size of the 'sorted' part of the list by one Note: for selection sort, swapping the element currently in the front position with the smallest element is faster than sliding all of the numbers down in the list.
    [Show full text]
  • Quick Sort Algorithm Song Qin Dept
    Quick Sort Algorithm Song Qin Dept. of Computer Sciences Florida Institute of Technology Melbourne, FL 32901 ABSTRACT each iteration. Repeat this on the rest of the unsorted region Given an array with n elements, we want to rearrange them in without the first element. ascending order. In this paper, we introduce Quick Sort, a Bubble sort works as follows: keep passing through the list, divide-and-conquer algorithm to sort an N element array. We exchanging adjacent element, if the list is out of order; when no evaluate the O(NlogN) time complexity in best case and O(N2) exchanges are required on some pass, the list is sorted. in worst case theoretically. We also introduce a way to approach the best case. Merge sort [4]has a O(NlogN) time complexity. It divides the 1. INTRODUCTION array into two subarrays each with N/2 items. Conquer each Search engine relies on sorting algorithm very much. When you subarray by sorting it. Unless the array is sufficiently small(one search some key word online, the feedback information is element left), use recursion to do this. Combine the solutions to brought to you sorted by the importance of the web page. the subarrays by merging them into single sorted array. 2 Bubble, Selection and Insertion Sort, they all have an O(N2) In Bubble sort, Selection sort and Insertion sort, the O(N ) time time complexity that limits its usefulness to small number of complexity limits the performance when N gets very big. element no more than a few thousand data points.
    [Show full text]
  • Overview of Sorting Algorithms
    Unit 7 Sorting Algorithms Simple Sorting algorithms Quicksort Improving Quicksort Overview of Sorting Algorithms Given a collection of items we want to arrange them in an increasing or decreasing order. You probably have seen a number of sorting algorithms including ¾ selection sort ¾ insertion sort ¾ bubble sort ¾ quicksort ¾ tree sort using BST's In terms of efficiency: ¾ average complexity of the first three is O(n2) ¾ average complexity of quicksort and tree sort is O(n lg n) ¾ but its worst case is still O(n2) which is not acceptable In this section, we ¾ review insertion, selection and bubble sort ¾ discuss quicksort and its average/worst case analysis ¾ show how to eliminate tail recursion ¾ present another sorting algorithm called heapsort Unit 7- Sorting Algorithms 2 Selection Sort Assume that data ¾ are integers ¾ are stored in an array, from 0 to size-1 ¾ sorting is in ascending order Algorithm for i=0 to size-1 do x = location with smallest value in locations i to size-1 swap data[i] and data[x] end Complexity If array has n items, i-th step will perform n-i operations First step performs n operations second step does n-1 operations ... last step performs 1 operatio. Total cost : n + (n-1) +(n-2) + ... + 2 + 1 = n*(n+1)/2 . Algorithm is O(n2). Unit 7- Sorting Algorithms 3 Insertion Sort Algorithm for i = 0 to size-1 do temp = data[i] x = first location from 0 to i with a value greater or equal to temp shift all values from x to i-1 one location forwards data[x] = temp end Complexity Interesting operations: comparison and shift i-th step performs i comparison and shift operations Total cost : 1 + 2 + ..
    [Show full text]
  • The Analysis and Synthesis of a Parallel Sorting Engine Redacted for Privacy Abstract Approv, John M
    AN ABSTRACT OF THE THESIS OF Byoungchul Ahn for the degree of Doctor of Philosophy in Electrical and Computer Engineering, presented on May 3. 1989. Title: The Analysis and Synthesis of a Parallel Sorting Engine Redacted for Privacy Abstract approv, John M. Murray / Thisthesisisconcerned withthe development of a unique parallelsort-mergesystemsuitablefor implementationinVLSI. Two new sorting subsystems, a high performance VLSI sorter and a four-waymerger,werealsorealizedduringthedevelopment process. In addition, the analysis of several existing parallel sorting architectures and algorithms was carried out. Algorithmic time complexity, VLSI processor performance, and chiparearequirementsfortheexistingsortingsystemswere evaluated.The rebound sorting algorithm was determined to be the mostefficientamongthoseconsidered. The reboundsorter algorithm was implementedinhardware asasystolicarraywith external expansion capability. The second phase of the research involved analyzing several parallel merge algorithms andtheirbuffer management schemes. The dominant considerations for this phase of the research were the achievement of minimum VLSI chiparea,design complexity, and logicdelay. Itwasdeterminedthattheproposedmerger architecture could be implemented inseveral ways. Selecting the appropriate microarchitecture for the merger, given the constraints of chip area and performance, was the major problem.The tradeoffs associated with this process are outlined. Finally,apipelinedsort-merge system was implementedin VLSI by combining a rebound sorter
    [Show full text]
  • Sorting Algorithms Correcness, Complexity and Other Properties
    Sorting Algorithms Correcness, Complexity and other Properties Joshua Knowles School of Computer Science The University of Manchester COMP26912 - Week 9 LF17, April 1 2011 The Importance of Sorting Important because • Fundamental to organizing data • Principles of good algorithm design (correctness and efficiency) can be appreciated in the methods developed for this simple (to state) task. Sorting Algorithms 2 LF17, April 1 2011 Every algorithms book has a large section on Sorting... Sorting Algorithms 3 LF17, April 1 2011 ...On the Other Hand • Progress in computer speed and memory has reduced the practical importance of (further developments in) sorting • quicksort() is often an adequate answer in many applications However, you still need to know your way (a little) around the the key sorting algorithms Sorting Algorithms 4 LF17, April 1 2011 Overview What you should learn about sorting (what is examinable) • Definition of sorting. Correctness of sorting algorithms • How the following work: Bubble sort, Insertion sort, Selection sort, Quicksort, Merge sort, Heap sort, Bucket sort, Radix sort • Main properties of those algorithms • How to reason about complexity — worst case and special cases Covered in: the course book; labs; this lecture; wikipedia; wider reading Sorting Algorithms 5 LF17, April 1 2011 Relevant Pages of the Course Book Selection sort: 97 (very short description only) Insertion sort: 98 (very short) Merge sort: 219–224 (pages on multi-way merge not needed) Heap sort: 100–106 and 107–111 Quicksort: 234–238 Bucket sort: 241–242 Radix sort: 242–243 Lower bound on sorting 239–240 Practical issues, 244 Some of the exercise on pp.
    [Show full text]
  • An Evolutionary Approach for Sorting Algorithms
    ORIENTAL JOURNAL OF ISSN: 0974-6471 COMPUTER SCIENCE & TECHNOLOGY December 2014, An International Open Free Access, Peer Reviewed Research Journal Vol. 7, No. (3): Published By: Oriental Scientific Publishing Co., India. Pgs. 369-376 www.computerscijournal.org Root to Fruit (2): An Evolutionary Approach for Sorting Algorithms PRAMOD KADAM AND Sachin KADAM BVDU, IMED, Pune, India. (Received: November 10, 2014; Accepted: December 20, 2014) ABstract This paper continues the earlier thought of evolutionary study of sorting problem and sorting algorithms (Root to Fruit (1): An Evolutionary Study of Sorting Problem) [1]and concluded with the chronological list of early pioneers of sorting problem or algorithms. Latter in the study graphical method has been used to present an evolution of sorting problem and sorting algorithm on the time line. Key words: Evolutionary study of sorting, History of sorting Early Sorting algorithms, list of inventors for sorting. IntroDUCTION name and their contribution may skipped from the study. Therefore readers have all the rights to In spite of plentiful literature and research extent this study with the valid proofs. Ultimately in sorting algorithmic domain there is mess our objective behind this research is very much found in documentation as far as credential clear, that to provide strength to the evolutionary concern2. Perhaps this problem found due to lack study of sorting algorithms and shift towards a good of coordination and unavailability of common knowledge base to preserve work of our forebear platform or knowledge base in the same domain. for upcoming generation. Otherwise coming Evolutionary study of sorting algorithm or sorting generation could receive hardly information about problem is foundation of futuristic knowledge sorting problems and syllabi may restrict with some base for sorting problem domain1.
    [Show full text]
  • Data Structures & Algorithms
    DATA STRUCTURES & ALGORITHMS Tutorial 6 Questions SORTING ALGORITHMS Required Questions Question 1. Many operations can be performed faster on sorted than on unsorted data. For which of the following operations is this the case? a. checking whether one word is an anagram of another word, e.g., plum and lump b. findin the minimum value. c. computing an average of values d. finding the middle value (the median) e. finding the value that appears most frequently in the data Question 2. In which case, the following sorting algorithm is fastest/slowest and what is the complexity in that case? Explain. a. insertion sort b. selection sort c. bubble sort d. quick sort Question 3. Consider the sequence of integers S = {5, 8, 2, 4, 3, 6, 1, 7} For each of the following sorting algorithms, indicate the sequence S after executing each step of the algorithm as it sorts this sequence: a. insertion sort b. selection sort c. heap sort d. bubble sort e. merge sort Question 4. Consider the sequence of integers 1 T = {1, 9, 2, 6, 4, 8, 0, 7} Indicate the sequence T after executing each step of the Cocktail sort algorithm (see Appendix) as it sorts this sequence. Advanced Questions Question 5. A variant of the bubble sorting algorithm is the so-called odd-even transposition sort . Like bubble sort, this algorithm a total of n-1 passes through the array. Each pass consists of two phases: The first phase compares array[i] with array[i+1] and swaps them if necessary for all the odd values of of i.
    [Show full text]
  • 13 Basic Sorting Algorithms
    Concise Notes on Data Structures and Algorithms Basic Sorting Algorithms 13 Basic Sorting Algorithms 13.1 Introduction Sorting is one of the most fundamental and important data processing tasks. Sorting algorithm: An algorithm that rearranges records in lists so that they follow some well-defined ordering relation on values of keys in each record. An internal sorting algorithm works on lists in main memory, while an external sorting algorithm works on lists stored in files. Some sorting algorithms work much better as internal sorts than external sorts, but some work well in both contexts. A sorting algorithm is stable if it preserves the original order of records with equal keys. Many sorting algorithms have been invented; in this chapter we will consider the simplest sorting algorithms. In our discussion in this chapter, all measures of input size are the length of the sorted lists (arrays in the sample code), and the basic operation counted is comparison of list elements (also called keys). 13.2 Bubble Sort One of the oldest sorting algorithms is bubble sort. The idea behind it is to make repeated passes through the list from beginning to end, comparing adjacent elements and swapping any that are out of order. After the first pass, the largest element will have been moved to the end of the list; after the second pass, the second largest will have been moved to the penultimate position; and so forth. The idea is that large values “bubble up” to the top of the list on each pass. A Ruby implementation of bubble sort appears in Figure 1.
    [Show full text]
  • Selection Sort
    CS50 Selection Sort Overview Key Terms Sorted arrays are typically easier to search than unsorted arrays. One algorithm to sort • selection sort is bubble sort. Intuitively, it seemed that there were lots of swaps involved; but perhaps • array there is another way? Selection sort is another sorting algorithm that minimizes the • pseudocode amount of swaps made (at least compared to bubble sort). Like any optimization, ev- erything comes at a cost. While this algorithm may not have to make as many swaps, it does increase the amount of comparing required to sort a single element. Implementation Selection sort works by splitting the array into two parts: a sorted array and an unsorted array. If we are given an array Step-by-step process for of the numbers 5, 1, 6, 2, 4, and 3 and we wanted to sort it selection sort using selection sort, our pseudocode might look something like this: 5 1 6 2 4 3 repeat for the amount of elements in the array find the smallest unsorted value swap that value with the first unsorted value When this is implemented on the example array, the pro- 1 5 6 2 4 3 gram would start at array[0] (which is 5). We would then compare every number to its right (1, 6, 2, 4, and 3), to find the smallest element. Finding that 1 is the smallest, it gets swapped with the element at the current position. Now 1 is 1 2 6 5 4 3 in the sorted part of the array and 5, 6, 2, 4, and 3 are still unsorted.
    [Show full text]
  • Sorting Partnership Unless You Sign Up! Brian Curless • Homework #5 Will Be Ready After Class, Spring 2008 Due in a Week
    Announcements (5/9/08) • Project 3 is now assigned. CSE 326: Data Structures • Partnerships due by 3pm – We will not assume you are in a Sorting partnership unless you sign up! Brian Curless • Homework #5 will be ready after class, Spring 2008 due in a week. • Reading for this lecture: Chapter 7. 2 Sorting Consistent Ordering • Input – an array A of data records • The comparison function must provide a – a key value in each data record consistent ordering on the set of possible keys – You can compare any two keys and get back an – a comparison function which imposes a indication of a < b, a > b, or a = b (trichotomy) consistent ordering on the keys – The comparison functions must be consistent • Output • If compare(a,b) says a<b, then compare(b,a) must say b>a • If says a=b, then must say b=a – reorganize the elements of A such that compare(a,b) compare(b,a) • If compare(a,b) says a=b, then equals(a,b) and equals(b,a) • For any i and j, if i < j then A[i] ≤ A[j] must say a=b 3 4 Why Sort? Space • How much space does the sorting • Allows binary search of an N-element algorithm require in order to sort the array in O(log N) time collection of items? • Allows O(1) time access to kth largest – Is copying needed? element in the array for any k • In-place sorting algorithms: no copying or • Sorting algorithms are among the most at most O(1) additional temp space.
    [Show full text]
  • Advanced Topics in Sorting
    Advanced Topics in Sorting complexity system sorts duplicate keys comparators 1 complexity system sorts duplicate keys comparators 2 Complexity of sorting Computational complexity. Framework to study efficiency of algorithms for solving a particular problem X. Machine model. Focus on fundamental operations. Upper bound. Cost guarantee provided by some algorithm for X. Lower bound. Proven limit on cost guarantee of any algorithm for X. Optimal algorithm. Algorithm with best cost guarantee for X. lower bound ~ upper bound Example: sorting. • Machine model = # comparisons access information only through compares • Upper bound = N lg N from mergesort. • Lower bound ? 3 Decision Tree a < b yes no code between comparisons (e.g., sequence of exchanges) b < c a < c yes no yes no a b c b a c a < c b < c yes no yes no a c b c a b b c a c b a 4 Comparison-based lower bound for sorting Theorem. Any comparison based sorting algorithm must use more than N lg N - 1.44 N comparisons in the worst-case. Pf. Assume input consists of N distinct values a through a . • 1 N • Worst case dictated by tree height h. N ! different orderings. • • (At least) one leaf corresponds to each ordering. Binary tree with N ! leaves cannot have height less than lg (N!) • h lg N! lg (N / e) N Stirling's formula = N lg N - N lg e N lg N - 1.44 N 5 Complexity of sorting Upper bound. Cost guarantee provided by some algorithm for X. Lower bound. Proven limit on cost guarantee of any algorithm for X.
    [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]