Quicksort, Bucket Sort, Radix Sort

Total Page:16

File Type:pdf, Size:1020Kb

Quicksort, Bucket Sort, Radix Sort Quick-Sort, Bucket Sort, Radix Sort Sections 11.2, 11.3.2, 11.3.3 7 4 9 6 2 → 2 4 6 7 9 4 2 → 2 4 7 9 → 7 9 2 → 2 9 → 9 © 2004 Goodrich, Tamassia Quick-Sort 1 Quick-Sort Quick-sort is a randomized sorting algorithm based x on the divide-and-conquer paradigm: ◼ Divide: pick a random element x (called pivot) and x partition S into L elements less than x E elements equal x L E G G elements greater than x ◼ Recur: sort L and G ◼ Conquer: join L, E and G x © 2004 Goodrich, Tamassia Quick-Sort 2 Partition We partition an input Algorithm partition(S, p) sequence as follows: Input sequence S, position p of pivot Output subsequences L, E, G of the ◼ We remove, in turn, each elements of S less than, equal to, element y from S and or greater than the pivot, resp. ◼ We insert y into L, E or G, L, E, G empty sequences depending on the result of x S.erase(p) the comparison with the while S.empty() pivot x y S.eraseFront() Each insertion and removal if y < x is at the beginning or at the L.insertBack(y) end of a sequence, and else if y = x hence takes O(1) time E.insertBack(y) Thus, the partition step of else { y > x } quick-sort takes O(n) time G.insertBack(y) return L, E, G © 2004 Goodrich, Tamassia Quick-Sort 3 Quick-Sort Tree An execution of quick-sort is depicted by a binary tree ◼ Each node represents a recursive call of quick-sort and stores Unsorted sequence before the execution and its pivot Sorted sequence at the end of the execution ◼ The root is the initial call ◼ The leaves are calls on subsequences of size 0 or 1 7 4 9 6 2 → 2 4 6 7 9 4 2 → 2 4 7 9 → 7 9 2 → 2 9 → 9 © 2004 Goodrich, Tamassia Quick-Sort 4 Execution Example Pivot selection 7 2 9 4 3 7 6 1 → 1 2 3 4 6 7 8 9 7 2 9 4 → 2 4 7 9 3 8 6 1 → 1 3 8 6 2 → 2 9 4 → 4 9 3 → 3 8 → 8 9 → 9 4 → 4 © 2004 Goodrich, Tamassia Quick-Sort 5 Execution Example (cont.) Partition, recursive call, pivot selection 7 2 9 4 3 7 6 1 → 1 2 3 4 6 7 8 9 2 4 3 1 → 2 4 7 9 3 8 6 1 → 1 3 8 6 2 → 2 9 4 → 4 9 3 → 3 8 → 8 9 → 9 4 → 4 © 2004 Goodrich, Tamassia Quick-Sort 6 Execution Example (cont.) Partition, recursive call, base case 7 2 9 4 3 7 6 1 → → 1 2 3 4 6 7 8 9 2 4 3 1 →→ 2 4 7 3 8 6 1 → 1 3 8 6 1 → 1 9 4 → 4 9 3 → 3 8 → 8 9 → 9 4 → 4 © 2004 Goodrich, Tamassia Quick-Sort 7 Execution Example (cont.) Recursive call, …, base case, join 7 2 9 4 3 7 6 1 → 1 2 3 4 6 7 8 9 2 4 3 1 → 1 2 3 4 3 8 6 1 → 1 3 8 6 1 → 1 4 3 → 3 4 3 → 3 8 → 8 9 → 9 4 → 4 © 2004 Goodrich, Tamassia Quick-Sort 8 Execution Example (cont.) Recursive call, pivot selection 7 2 9 4 3 7 6 1 → 1 2 3 4 6 7 8 9 2 4 3 1 → 1 2 3 4 7 9 7 1 → 1 3 8 6 1 → 1 4 3 → 3 4 8 → 8 9 → 9 9 → 9 4 → 4 © 2004 Goodrich, Tamassia Quick-Sort 9 Execution Example (cont.) Partition, …, recursive call, base case 7 2 9 4 3 7 6 1 → 1 2 3 4 6 7 8 9 2 4 3 1 → 1 2 3 4 7 9 7 1 → 1 3 8 6 1 → 1 4 3 → 3 4 8 → 8 9 → 9 9 → 9 4 → 4 © 2004 Goodrich, Tamassia Quick-Sort 10 Execution Example (cont.) Join, join 7 2 9 4 3 7 6 1 → 1 2 3 4 6 7 7 9 2 4 3 1 → 1 2 3 4 7 9 7 → 17 7 9 1 → 1 4 3 → 3 4 8 → 8 9 → 9 9 → 9 4 → 4 © 2004 Goodrich, Tamassia Quick-Sort 11 Worst-case Running Time The worst case for quick-sort occurs when the pivot is the unique minimum or maximum element One of L and G has size n - 1 and the other has size 0 The running time is proportional to the sum n + (n - 1) + … + 2 + 1 Thus, the worst-case running time of quick-sort is O(n2) depth time 0 n 1 n - 1 … … n - 1 1 © 2004 Goodrich, Tamassia Quick-Sort 12 Expected Running Time Consider a recursive call of quick-sort on a sequence of size s ◼ Good call: the sizes of L and G are each less than 3s/4 ◼ Bad call: one of L and G has size greater than 3s/4 7 2 9 4 3 7 6 1 9 7 2 9 8 4 3 7 6 1 2 4 3 1 7 9 7 1 → 1 1 7 9 8 4 3 7 6 Good call Bad call A call is good with probability 1/2 ◼ 1/2 of the possible pivots cause good calls: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Bad pivots Good pivots Bad pivots © 2004 Goodrich, Tamassia Quick-Sort 13 Expected Running Time, Part 2 Probabilistic Fact: The expected number of coin tosses required in order to get k heads is 2k For a node of depth i, we expect ◼ i/2 ancestors are good calls i/2 ◼ The size of the input sequence for the current call is at most (3/4) n Therefore, we have expected height time per level s(r) O(n) ◼ For a node of depth 2log4/3n, the expected input size is one ◼ The expected height of the s(a) s(b) O(n) quick-sort tree is O(log n) O(log n) The amount or work done at the s(c) s(d) s(e) s(f) O(n) nodes of the same depth is O(n) Thus, the expected running time of quick-sort is O(n log n) total expected time: O(n log n) © 2004 Goodrich, Tamassia Quick-Sort 14 In-Place Quick-Sort Quick-sort can be implemented to run in-place In the partition step, we use Algorithm inPlaceQuickSort(S, l, r) replace operations to rearrange Input sequence S, ranks l and r the elements of the input Output sequence S with the sequence such that elements of rank between l and r rearranged in increasing order ◼ the elements less than the pivot have rank less than h if l r return ◼ the elements equal to the pivot have rank between h and k i a random integer between l and r ◼ the elements greater than the x S.elemAtRank(i) pivot have rank greater than k (h, k) inPlacePartition(x) The recursive calls consider inPlaceQuickSort(S, l, h - 1) ◼ elements with rank less than h inPlaceQuickSort(S, k + 1, r) ◼ elements with rank greater than k © 2004 Goodrich, Tamassia Quick-Sort 15 In-Place Partitioning Perform the partition using two indices to split S into L and E U G (a similar method can split E U G into E and G). j k 3 2 5 1 0 7 3 5 9 2 7 9 8 9 7 6 9 (pivot = 6) Repeat until j and k cross: ◼ Scan j to the right until finding an element > x. ◼ Scan k to the left until finding an element < x. ◼ Swap elements at indices j and k j k 3 2 5 1 0 7 3 5 9 2 7 9 8 9 7 6 9 © 2004 Goodrich, Tamassia Quick-Sort 16 Summary of Sorting Algorithms Algorithm Time Notes ▪ in-place selection-sort O(n2) ▪ slow (good for small inputs) ▪ in-place insertion-sort O(n2) ▪ slow (good for small inputs) O(n log n) ▪ in-place, randomized quick-sort expected ▪ fastest (good for large inputs) ▪ in-place heap-sort O(n log n) ▪ fast (good for large inputs) ▪ sequential data access merge-sort O(n log n) ▪ fast (good for huge inputs) © 2004 Goodrich, Tamassia Quick-Sort 17 Bucket-Sort Let be S be a sequence of n Algorithm bucketSort(S, N) (key, element) entries with Input sequence S of (key, element) keys in the range [0, N - 1] items with keys in the range Bucket-sort uses the keys as [0, N - 1] indices into an auxiliary array B Output sequence S sorted by of sequences (buckets) increasing keys Phase 1: Empty sequence S by B array of N empty sequences moving each entry (k, o) into while S.empty() its bucket B[k] (k, o) S.front() Phase 2: For i = 0, …, N - 1, move S.eraseFront() the entries of bucket B[i] to the B[k].insertBack((k, o)) end of sequence S for i 0 to N - 1 Analysis: while B[i].empty() ◼ Phase 1 takes O(n) time (k, o) B[i].front() ◼ Phase 2 takes O(n + N) time B[i].eraseFront() Bucket-sort takes O(n + N) time S.insertBack((k, o)) © 2004 Goodrich, Tamassia Bucket-Sort and Radix-Sort 18 Example Key range [0, 9] 7, d 1, c 3, a 7, g 3, b 7, e Phase 1 1, c 3, a 3, b 7, d 7, g 7, e B 0 1 2 3 4 5 6 7 8 9 Phase 2 1, c 3, a 3, b 7, d 7, g 7, e © 2004 Goodrich, Tamassia Bucket-Sort and Radix-Sort 19 Properties and Extensions Key-type Property Extensions ◼ The keys are used as ◼ Integer keys in the range [a, b] indices into an array Put entry (k, o) into bucket and cannot be arbitrary B[k - a] objects ◼ String keys from a set D of possible strings, where D has ◼ No external comparator constant size (e.g., names of Stable Sort Property the 13 provinces and territories) ◼ The relative order of Sort D and compute the rank any two items with the r(k) of each string k of D in same key is preserved the sorted sequence after the execution of Put entry (k, o) into bucket the algorithm B[r(k)] © 2004 Goodrich, Tamassia Bucket-Sort and Radix-Sort 20 Lexicographic Order A d-tuple is a sequence of d keys (k1, k2, …, kd), where key ki is said to be the i-th dimension of the tuple Example: ◼ The Cartesian coordinates of a point in space are a 3-tuple The lexicographic order of two d-tuples is recursively defined as follows (x1, x2, …, xd) < (y1, y2, …, yd) x1 < y1 x1 = y1 (x2, …, xd) < (y2, …, yd) I.e., the tuples are compared by the first dimension, then by the second dimension, etc.
Recommended publications
  • Radix Sort Comparison Sort Runtime of O(N*Log(N)) Is Optimal
    Radix Sort Comparison sort runtime of O(n*log(n)) is optimal • The problem of sorting cannot be solved using comparisons with less than n*log(n) time complexity • See Proposition I in Chapter 2.2 of the text How can we sort without comparison? • Consider the following approach: • Look at the least-significant digit • Group numbers with the same digit • Maintain relative order • Place groups back in array together • I.e., all the 0’s, all the 1’s, all the 2’s, etc. • Repeat for increasingly significant digits The characteristics of Radix sort • Least significant digit (LSD) Radix sort • a fast stable sorting algorithm • begins at the least significant digit (e.g. the rightmost digit) • proceeds to the most significant digit (e.g. the leftmost digit) • lexicographic orderings Generally Speaking • 1. Take the least significant digit (or group of bits) of each key • 2. Group the keys based on that digit, but otherwise keep the original order of keys. • This is what makes the LSD radix sort a stable sort. • 3. Repeat the grouping process with each more significant digit Generally Speaking public static void sort(String [] a, int W) { int N = a.length; int R = 256; String [] aux = new String[N]; for (int d = W - 1; d >= 0; --d) { aux = sorted array a by the dth character a = aux } } A Radix sort example A Radix sort example A Radix sort example • Problem: How to ? • Group the keys based on that digit, • but otherwise keep the original order of keys. Key-indexed counting • 1. Take the least significant digit (or group of bits) of each key • 2.
    [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]
  • Tutorial 2: Heapsort, Quicksort, Counting Sort, Radix Sort
    Tutorial 2: Heapsort, Quicksort, Counting Sort, Radix Sort Mayank Saksena September 20, 2006 1 Heapsort We review Heapsort, and prove some loop invariants for it. For further information, see Chapter 6 of Introduction to Algorithms. HEAPSORT(A) 1 BUILD-MAX-HEAP(A) Ð eÒg Øh A 2 for i = ( ) downto 2 A i 3 swap A[1] and [ ] ×iÞ e A heaÔ ×iÞ e A 4 heaÔ- ( )= - ( ) 1 5 MAX-HEAPIFY(A; 1) BUILD-MAX-HEAP(A) ×iÞ e A Ð eÒg Øh A 1 heaÔ- ( )= ( ) Ð eÒg Øh A = 2 for i = ( ) 2 downto 1 3 MAX-HEAPIFY(A; i) MAX-HEAPIFY(A; i) i 1 Ð =LEFT( ) i 2 Ö =RIGHT( ) heaÔ ×iÞ e A A Ð > A i Ð aÖ g eר Ð 3 if Ð - ( ) and ( ) ( ) then = i 4 else Ð aÖ g eר = heaÔ ×iÞ e A A Ö > A Ð aÖ g eר Ð aÖ g eר Ö 5 if Ö - ( ) and ( ) ( ) then = i 6 if Ð aÖ g eר = i A Ð aÖ g eר 7 swap A[ ] and [ ] 8 MAX-HEAPIFY(A; Ð aÖ g eר) 1 Loop invariants First, assume that MAX-HEAPIFY(A; i) is correct, i.e., that it makes the subtree with A root i a max-heap. Under this assumption, we prove that BUILD-MAX-HEAP( ) is correct, i.e., that it makes A a max-heap. A We show: at the start of iteration i of the for-loop of BUILD-MAX-HEAP( ) (line ; i ;:::;Ò 2), each of the nodes i +1 +2 is the root of a max-heap.
    [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]
  • Sorting Algorithm 1 Sorting Algorithm
    Sorting algorithm 1 Sorting algorithm 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) which require input data to be in sorted lists; 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 (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 2006). 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 upper and lower bounds. Classification Sorting algorithms are often classified by: • Computational complexity (worst, average and best behavior) of element comparisons in terms of the size of the list (n). For typical serial sorting algorithms good behavior is O(n log n), with parallel sort in O(log2 n), and bad behavior is O(n2).
    [Show full text]
  • Parallel Sorting on Multi-Core Architecture
    Parallel Sorting on Multi-core Architecture A thesis submitted in partial fulfillment of the requirements for the degree of Master of Science By Wei Wang B.S., Zhengzhou University, 2007 2011 Wright State University WRIGHT STATE UNIVERSITY SCHOOL OF GRADUATE STUDIES August 19, 2011 I HEREBY RECOMMEND THAT THE THESIS PREPARED UNDER MY SUPER- VISION BY Wei Wang ENTITLED Parallel Sorting on Multi-core Architecture BE ACCEPTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF Master of Science. Meilin Liu, Ph. D. Thesis Director Mateen Rizki, Ph.D. Department Chair Committee on Final Examination Meilin Liu, Ph. D. Jack Jean, Ph. D. T.K. Prasad, Ph. D. Andrew Hsu, Ph. D. Dean, School of Graduate Studies Copyright c 2011 Wei Wang All Rights Reserved ABSTRACT Wang, Wei. M.S. Department of Computer Science and Engineering, Wright State University, 2011. Parallel Sorting on Multi-Core Architecture. With the limitations given by the power consumption (power wall), memory wall and the instruction level parallelism, the computing industry has turned its direc- tion to multi-core architectures. Nowadays, the multi-core and many-core architectures are becoming the trend of the processor design. But how to exploit these architectures is the primary challenge for the research community. To take advantage of the multi- core architectures, the software design has undergone fundamental changes. Sorting is a fundamental, important problem in computer science. It is utilized in many applications such as databases and search engines. In this thesis, we will in- vestigate and auto-tune two parallel sorting algorithms, i.e., radix sort and sample sort on two parallel architectures, the many-core nVIDIA CUDA enabled graphics proces- sors, and the multi-core Cell Broadband Engine.
    [Show full text]
  • Comparison of Parallel Sorting Algorithms
    Comparison of parallel sorting algorithms Darko Božidar and Tomaž Dobravec Faculty of Computer and Information Science, University of Ljubljana, Slovenia Technical report November 2015 TABLE OF CONTENTS 1. INTRODUCTION .................................................................................................... 3 2. THE ALGORITHMS ................................................................................................ 3 2.1 BITONIC SORT ........................................................................................................................ 3 2.2 MULTISTEP BITONIC SORT ................................................................................................. 3 2.3 IBR BITONIC SORT ................................................................................................................ 3 2.4 MERGE SORT .......................................................................................................................... 4 2.5 QUICKSORT ............................................................................................................................ 4 2.6 RADIX SORT ........................................................................................................................... 4 2.7 SAMPLE SORT ........................................................................................................................ 4 3. TESTING ENVIRONMENT .................................................................................... 5 4. RESULTS ................................................................................................................
    [Show full text]
  • Discussion 10 Solution Fall 2015 1 Sorting I Show the Steps Taken by Each Sort on the Following Unordered List
    CS 61B Discussion 10 Solution Fall 2015 1 Sorting I Show the steps taken by each sort on the following unordered list: 106, 351, 214, 873, 615, 172, 333, 564 (a) Quicksort (assume the pivot is always the first item in the sublist being sorted and the array is sorted in place). At every step circle everything that will be a pivot on the next step and box all previous pivots. 106 351 214 873 615 172 333 564 £ 106 351 214 873 615 172 333 564 ¢ ¡ £ 106 214 172 333 351 873 615 564 £¢ ¡ £ 106 172 214 333 351 615 564 873 ¢ ¡ £¢ ¡ 106 172 214 333 351 564 615 873 ¢ ¡ (b) Merge sort. Show the intermediate merging steps. 106 351 214 873 615 172 333 564 106 351 214 873 172 615 333 564 106 214 351 873 172 333 564 615 106 214 351 873 172 333 564 615 106 172 214 333 351 564 615 873 (c) LSD radix sort. 106 351 214 873 615 172 333 564 351 172 873 333 214 564 615 106 106 214 615 333 351 564 172 873 106 172 214 333 351 564 615 873 2 Sorting II Match the sorting algorithms to the sequences, each of which represents several intermediate steps in the sorting of an array of integers. Algorithms: Quicksort, merge sort, heapsort, MSD radix sort, insertion sort. CS 61B, Fall 2015, Discussion 10 Solution 1 (a) 12, 7, 8, 4, 10, 2, 5, 34, 14 7, 8, 4, 10, 2, 5, 12, 34, 14 4, 2, 5, 7, 8, 10, 12, 14, 34 Quicksort (b) 23, 45, 12, 4, 65, 34, 20, 43 12, 23, 45, 4, 65, 34, 20, 43 Insertion sort (c) 12, 32, 14, 11, 17, 38, 23, 34 12, 14, 11, 17, 23, 32, 38, 34 MSD radix sort (d) 45, 23, 5, 65, 34, 3, 76, 25 23, 45, 5, 65, 3, 34, 25, 76 5, 23, 45, 65, 3, 25, 34, 76 Merge sort (e) 23, 44, 12, 11, 54, 33, 1, 41 54, 44, 33, 41, 23, 12, 1, 11 44, 41, 33, 11, 23, 12, 1, 54 Heap sort 3 Runtimes Fill in the best and worst case runtimes of the following sorting algorithms with respect to n, the length of the list being sorted, along with when that runtime would occur.
    [Show full text]
  • A Comparative Study of Sorting Algorithms Comb, Cocktail and Counting Sorting
    International Research Journal of Engineering and Technology (IRJET) e‐ISSN: 2395 ‐0056 Volume: 04 Issue: 01 | Jan ‐2017 www.irjet.net p‐ISSN: 2395‐0072 A comparative Study of Sorting Algorithms Comb, Cocktail and Counting Sorting Ahmad H. Elkahlout1, Ashraf Y. A. Maghari2. 1 Faculty of Information Technology, Islamic University of Gaza ‐ Palestine 2 Faculty of Information Technology, Islamic University of Gaza ‐ Palestine ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐***‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ Abstract –The sorting algorithms problem is probably one java programming language, in which every algorithm sort of the most famous problems that used in abroad variety of the same set of random numeric data. Then the execution time during the sorting process is measured for each application. There are many techniques to solve the sorting algorithm. problem. In this paper, we conduct a comparative study to evaluate the performance of three algorithms; comb, cocktail The rest part of this paper is organized as follows. Section 2 and count sorting algorithms in terms of execution time. Java gives a background of the three algorithms; comb, count, and programing is used to implement the algorithms using cocktail algorithms. In section 3, related work is presented. numeric data on the same platform conditions. Among the Section4 comparison between the algorithms; section 5 three algorithms, we found out that the cocktail algorithm has discusses the results obtained from the evaluation of sorting the shortest execution time; while counting sort comes in the techniques considered. The paper is concluded in section 6. second order. Furthermore, Comb comes in the last order in term of execution time. Future effort will investigate the 2.
    [Show full text]
  • Register Level Sort Algorithm on Multi-Core SIMD Processors
    Register Level Sort Algorithm on Multi-Core SIMD Processors Tian Xiaochen, Kamil Rocki and Reiji Suda Graduate School of Information Science and Technology The University of Tokyo & CREST, JST {xchen, kamil.rocki, reiji}@is.s.u-tokyo.ac.jp ABSTRACT simultaneously. GPU employs a similar architecture: single- State-of-the-art hardware increasingly utilizes SIMD paral- instruction-multiple-threads(SIMT). On K20, each SMX has lelism, where multiple processing elements execute the same 192 CUDA cores which act as individual threads. Even a instruction on multiple data points simultaneously. How- desktop type multi-core x86 platform such as i7 Haswell ever, irregular and data intensive algorithms are not well CPU family supports AVX2 instruction set (256 bits). De- suited for such architectures. Due to their importance, it veloping algorithms that support multi-core SIMD architec- is crucial to obtain efficient implementations. One example ture is the precondition to unleash the performance of these of such a task is sort, a fundamental problem in computer processors. Without exploiting this kind of parallelism, only science. In this paper we analyze distinct memory accessing a small fraction of computational power can be utilized. models and propose two methods to employ highly efficient Parallel sort as well as sort in general is fundamental and bitonic merge sort using SIMD instructions as register level well studied problem in computer science. Algorithms such sort. We achieve nearly 270x speedup (525M integers/s) on as Bitonic-Merge Sort or Odd Even Merge Sort are widely a 4M integer set using Xeon Phi coprocessor, where SIMD used in practice.
    [Show full text]
  • Different Sorting Algorithm's Comparison Based Upon the Time
    International Journal of u- and e- Service, Science and Technology Vol.9, No. 8 (2016), pp.287-296 http://dx.doi.org/10.14257/ijunesst.2016.9.8.24 Different Sorting Algorithm’s Comparison based Upon the Time Complexity D. Rajagopal1* and K. Thilakavalli2 1Assistant Professor, Department of Computer Applications, KSR College of Arts and Science(Autonomous), Tiruchengode, Namakkal Dt, Tamilnadu, India 2Assistant Professor, Department of Computer Applications, KSR College of Arts and Science(Autonomous), Tiruchengode, Namakkal Dt, Tamilnadu, India [email protected],[email protected] Abstract In this paper the different sorting algorithms execution time has been examined with different number of elements. Through this experimental result concluded that the algorithm which is working best. The analysis, execution time has analyzed, tabulated in Microsoft Excel. The sorting problem has attracted a great deal of study, possibly due to the complexity of solving it proficiently despite its simple, familiar statement. Sorting algorithms are established in opening computer science classes, where the abundance of algorithms for the problem provides a gentle beginning to variety of core algorithm concepts. Objective of this paper is finding the best sorting algorithm. Keywords: Sorting algorithm, Time Complexity, Efficiency, Execution Time, Quick Sort, Selection Sort 1. Introduction Sorting algorithm is an algorithm in that the most-used orders are numerical order and lexicographical order in computer science and mathematics. Proficient sorting is vital for optimizing the utilization of other algorithms that require sorted lists to work correctly. More properly, the output must gratify two circumstances: (1) The output is in non decreasing order and (2) The output is a variation, or reordering, of the input.
    [Show full text]
  • 7 Internal Sorting and Quicksort) by Taking Advantage of the Best Case Behavior of Another Algorithm (Insertion Sort)
    7 Internal Sorting We sort many things in our everyday lives: A handful of cards when playing Bridge; bills and other piles of paper; jars of spices; and so on. And we have many intuitive strategies that we can use to do the sorting, depending on how many objects we have to sort and how hard they are to move around. Sorting is also one of the most frequently performed computing tasks. We might sort the records in a database so that we can search the collection efficiently. We might sort the records by zip code so that we can print and mail them more cheaply. We might use sorting as an intrinsic part of an algorithm to solve some other problem, such as when computing the minimum-cost spanning tree (see Section 11.5). Because sorting is so important, naturally it has been studied intensively and many algorithms have been devised. Some of these algorithms are straightforward adaptations of schemes we use in everyday life. Others are totally alien to how hu- mans do things, having been invented to sort thousands or even millions of records stored on the computer. After years of study, there are still unsolved problems related to sorting. New algorithms are still being developed and refined for special- purpose applications. While introducing this central problem in computer science, this chapter has a secondary purpose of illustrating many important issues in algorithm design and analysis. The collection of sorting algorithms presented will illustate that divide- and-conquer is a powerful approach to solving a problem, and that there are multi- ple ways to do the dividing.
    [Show full text]