Heaps with Bits

Total Page:16

File Type:pdf, Size:1020Kb

Heaps with Bits Theoretical Computer Science ELSEVIER Theoretical Computer Science 164 (1996) 1-12 Heaps with bits Svante Carlsson a, Jingsen Chen a,*, Christer Mat&son b a Department of Computer Science, Luled University, S-971 87 Luled Sweden b Quality Laboratories AB, IDEON Research Park, S-223 70 Lund, Sweden Received March 1995; revised July 1995 Communicated by M. Nivat Abstract In this paper, we show how to improve the complexity of heap operations and heapsort using extra bits. We first study the parallel complexity of implementing priority queue operations on a heap. The trade-off between the number of extra bits used, the number of processors available, and the parallel time complexity is derived. While inserting a new element into a heap in parallel can be done as fast as parallel searching in a sorted list, we show how to delete the smallest element from a heap in constant time with a sublinear number of processors, and in sublogarithmic time with a sublogarithmic number of processors. The models of parallel computation used are the CREW PRAM and the CRCW PRAM. Our results improve those of previously known algorithms. Moreover, we study a variant, the fine-heap, of the traditional heap structure. A fast algorithm for constructing this new data structure is designed using an interesting technique, which is also used to develop an improved heapsort algorithm. Our variation of heapsort is faster than Wegener’s heapsort and requires less extra space. 1. Introduction One of the fundamental data types in Computer Science is the priority queue. It has been useful in many applications [l 11. A priority queue is a set of elements on which two basic operations are defined: inserting a new element into the set and deleting the minimum element from the set. Several data structures have been proposed for implementing priority queues. Probably the most elegant one is the heap [21]. A (min-)heap is a binary tree with heap-property: (i) It has the heap shape; i.e., all leaves lie on at most two levels which are adjacent and all leaves on the last level occupy the leftmost positions and all other levels are complete; (ii) It is min-ordered: the key value associated with each node is not smaller than that of its parent. The minimum element is then at the root, which is at the first level. We refer to the number of elements in a heap as its size. A max-heap is defined similarly. * Corresponding author. E-mail: svante,[email protected]. 0304-3975/96/$15.00 @ 1996- Elsevier Science B.V. All rights reserved SSDZ 0304-3975(95)00152-2 2 S. Carlsson, et al. I Theoretical Computer Science 164 (1996) I-12 The problem of heap construction and heap operations have received considerable attention in the literature [2,5,6,8,9, 11, 131. In the parallel models of computation, op- timal heap construction algorithms have also been developed [4,15]. However, parallel heap operations have not been so deeply studied. Recently, Pinotti and Pucci [14] pre- sented an O(log log n)-time ’ parallel algorithm for deleting the smallest element from a heap of size n using n/logn EREW-PRAM processors; and Zhang and Korf [22] reduced the number of processors used for the deletion to (n/logn)‘-‘ik for some constant k, 1 <k d [log(n/logn)l. In this paper, the trade-off between the number of extra bits used, the number of processors available, and the parallel-time complexity of heap operations is investigated. We first present a constant-time parallel deletion algo- rithm on the concurrent-read concurrent-write (CRCW) PRAM model. On this model, a multiple-write access to the same memory location succeeds only when all the pro- cessors writing to that cell are attempting to write the same value. Next, we show how to perform a delete operation in a heap of size n in O(logn/loglogn) time using log n/log log n processors on the same model. All our CRCW-PRAM algorithms use n extra bits. Moreover, if n log n extra bits are available and if a processor can write 0 or 1 into the bit of a word (where a word is of [logn] bits), the complexity of our parallel algorithms remains the same on the concurrent-read exclusive-write (CREW) PRAM model. Sorting is a fundamental algorithmic problem. One of the well studied in-place sort- ing algorithm is the heapsort, which first constructs a heap on the input elements and then deletes the elements one by one from the heap. The classical heapsort [8,21] needs 2n logn + 0(n) comparisons both in the worst and average cases to sort n elements [ 161. During the past 30 years, several variants of heapsort have been devel- oped [2,3,9, 10, 13, 19,201. The fastest one is the variant proposed by Wegener [19], which takes n logn+ l.ln (and n logn+n for n = 2’- 1) comparisons in the worst case, using n bits of extra storage. Moreover, it also makes Lo(n log n) two-bit variable com- parisons. This is very close to the information-theoretic lower bound of n log n- 1.4427n comparisons for sorting n elements. In Section 3, we shall study a new variant, the fine-heap, of the traditional heap structure, which is a heap with additional order- ing relation defined on siblings. Efficient construction algorithm for this new structure is presented. This algorithm is not only simple and fast, but also employs a powerful technique for designing comparison-based algorithms (namely, mass productions, which was previously used for designing the fastest known selection algorithm [ 171). With the fine-heap, we show how to obtain a variant of Wegener’s heapsort and achieve an upper bound of n log n + 1.00274n (and n log n + 0.91667n for n = 2h - 1) compar- isons in the worst case. Furthermore, our variant requires either Ln/2j extra bits and Co(nlogn) two-bit variable comparisons, or n extra bits and no bit comparisons. Re- mark that parallel algorithms for heap construction and heap operations can be adapted to the fine-heap, which may also result in a parallel version of heapsort. ’ All logarithms in this Paper are to base 2. S. Carlsson, et al. I Theoretical Computer Science 164 (1996) I-12 2. Parallel heap operations Notice that a heap on n elements can be stored level by level from left to right in an array X with the property that the element at position i has its parent at Li/2J and its children at 2i and 2i + 1. Thus, the addresses of all the nodes on a path from the root to some leaf of a heap can easily be computed by shift operations. The level, leuel(X[i]), of an element X[i] in the heap Y? is defined as LlogiJ + 1. For the insertion of a new element x into a heap 2 of size n, an optimal sequential algorithm of @(log logn) comparisons works as follow: First, x is placed at the first available position X[n + 11; and then the min-ordering is (re)stored on the path from X[l] down to X’[n + 11. This is equivalent to the problem of searching x in the path from X[l] to X[ [(n + 1)/2J] (which form a sorted list). For the complexity of parallel searching, see [ 12, 181. Therefore, the following observation is immediate. Observation 2.1. The parallel complexity of the insert operation in a heap of size n is the same as that of searching in a sorted list of length [log(n + l)] on the same model of parallel computation. The delete operation in a heap $4?[ 1.. n] consists of first removing the smallest element from the heap, replacing it with X[n], and then restoring the min-ordering property. The sequential deletion can be done optimally in logarithmic time. However, it appears that the delete operation is inherently sequential, since the operation involves the search of Z’[n] in some path from either ~$721 or ~4731 down to the leaf-level (called the path of minimum children). Hence, the deletion may not admit an efficient parallel solution. Observing that the searching path for Z’[n] is not known beforehand, we have Observation 2.2. In a heap, the parallel complexity of the delete operation is at least as hard as that of parallel insertion. In the rest of this section, nevertheless, we will try to parallelize the delete operation. More precisely, we shall demonstrate that it is possible to perform the deletion in constant time with a sublinear number of processors, and in sublogarithmic time using a sublogarithmic number of processors. Assume without loss of generality that the size of the heap is of form 2h - 1 for some integer h > 0. Otherwise, one can first perform the parallel deletion on the first [log n] levels of the heap and then in O( 1) steps find out which element at the leaf-level of the heap is the last node of the path of minimum children. We first show that the root deletion in a heap of size n can be solved in constant time with CJ(nlog n) processors on the CRCW PRAM model. Algorithm 2.3. Suppose the number of processors available is p = (n + 1)/2(LlognJ - 1). 4 S. Carlsson. et al. I Theoretical Computer Science 164 (1996) I-12 1. Associate with the heap X an array of n bits, denoted by B[ 1..n].
Recommended publications
  • Overview Parallel Merge Sort
    CME 323: Distributed Algorithms and Optimization, Spring 2015 http://stanford.edu/~rezab/dao. Instructor: Reza Zadeh, Matriod and Stanford. Lecture 4, 4/6/2016. Scribed by Henry Neeb, Christopher Kurrus, Andreas Santucci. Overview Today we will continue covering divide and conquer algorithms. We will generalize divide and conquer algorithms and write down a general recipe for it. What's nice about these algorithms is that they are timeless; regardless of whether Spark or any other distributed platform ends up winning out in the next decade, these algorithms always provide a theoretical foundation for which we can build on. It's well worth our understanding. • Parallel merge sort • General recipe for divide and conquer algorithms • Parallel selection • Parallel quick sort (introduction only) Parallel selection involves scanning an array for the kth largest element in linear time. We then take the core idea used in that algorithm and apply it to quick-sort. Parallel Merge Sort Recall the merge sort from the prior lecture. This algorithm sorts a list recursively by dividing the list into smaller pieces, sorting the smaller pieces during reassembly of the list. The algorithm is as follows: Algorithm 1: MergeSort(A) Input : Array A of length n Output: Sorted A 1 if n is 1 then 2 return A 3 end 4 else n 5 L mergeSort(A[0, ..., 2 )) n 6 R mergeSort(A[ 2 , ..., n]) 7 return Merge(L, R) 8 end 1 Last lecture, we described one way where we can take our traditional merge operation and translate it into a parallelMerge routine with work O(n log n) and depth O(log n).
    [Show full text]
  • Lecture 16: Lower Bounds for Sorting
    Lecture Notes CMSC 251 To bound this, recall the integration formula for bounding summations (which we paraphrase here). For any monotonically increasing function f(x) Z Xb−1 b f(i) ≤ f(x)dx: i=a a The function f(x)=xln x is monotonically increasing, and so we have Z n S(n) ≤ x ln xdx: 2 If you are a calculus macho man, then you can integrate this by parts, and if you are a calculus wimp (like me) then you can look it up in a book of integrals Z n 2 2 n 2 2 2 2 x x n n n n x ln xdx = ln x − = ln n − − (2 ln 2 − 1) ≤ ln n − : 2 2 4 x=2 2 4 2 4 This completes the summation bound, and hence the entire proof. Summary: So even though the worst-case running time of QuickSort is Θ(n2), the average-case running time is Θ(n log n). Although we did not show it, it turns out that this doesn’t just happen much of the time. For large values of n, the running time is Θ(n log n) with high probability. In order to get Θ(n2) time the algorithm must make poor choices for the pivot at virtually every step. Poor choices are rare, and so continuously making poor choices are very rare. You might ask, could we make QuickSort deterministic Θ(n log n) by calling the selection algorithm to use the median as the pivot. The answer is that this would work, but the resulting algorithm would be so slow practically that no one would ever use it.
    [Show full text]
  • Space-Efficient Data Structures, Streams, and Algorithms
    Andrej Brodnik Alejandro López-Ortiz Venkatesh Raman Alfredo Viola (Eds.) Festschrift Space-Efficient Data Structures, Streams, LNCS 8066 and Algorithms Papers in Honor of J. Ian Munro on the Occasion of His 66th Birthday 123 Lecture Notes in Computer Science 8066 Commenced Publication in 1973 Founding and Former Series Editors: Gerhard Goos, Juris Hartmanis, and Jan van Leeuwen Editorial Board David Hutchison Lancaster University, UK Takeo Kanade Carnegie Mellon University, Pittsburgh, PA, USA Josef Kittler University of Surrey, Guildford, UK Jon M. Kleinberg Cornell University, Ithaca, NY, USA Alfred Kobsa University of California, Irvine, CA, USA Friedemann Mattern ETH Zurich, Switzerland John C. Mitchell Stanford University, CA, USA Moni Naor Weizmann Institute of Science, Rehovot, Israel Oscar Nierstrasz University of Bern, Switzerland C. Pandu Rangan Indian Institute of Technology, Madras, India Bernhard Steffen TU Dortmund University, Germany Madhu Sudan Microsoft Research, Cambridge, MA, USA Demetri Terzopoulos University of California, Los Angeles, CA, USA Doug Tygar University of California, Berkeley, CA, USA Gerhard Weikum Max Planck Institute for Informatics, Saarbruecken, Germany Andrej Brodnik Alejandro López-Ortiz Venkatesh Raman Alfredo Viola (Eds.) Space-Efficient Data Structures, Streams, and Algorithms Papers in Honor of J. Ian Munro on the Occasion of His 66th Birthday 13 Volume Editors Andrej Brodnik University of Ljubljana, Faculty of Computer and Information Science Ljubljana, Slovenia and University of Primorska,
    [Show full text]
  • A Complete Bibliography of Publications in Nordisk Tidskrift for Informationsbehandling, BIT, and BIT Numerical Mathematics
    A Complete Bibliography of Publications in Nordisk Tidskrift for Informationsbehandling, BIT,andBIT Numerical Mathematics Nelson H. F. Beebe University of Utah Department of Mathematics, 110 LCB 155 S 1400 E RM 233 Salt Lake City, UT 84112-0090 USA Tel: +1 801 581 5254 FAX: +1 801 581 4148 E-mail: [email protected], [email protected], [email protected] (Internet) WWW URL: http://www.math.utah.edu/~beebe/ 09 June 2021 Version 3.54 Title word cross-reference [3105, 328, 469, 655, 896, 524, 873, 455, 779, 946, 2944, 297, 1752, 670, 2582, 1409, 1987, 915, 808, 761, 916, 2071, 2198, 1449, 780, 959, 1105, 1021, 497, 2589]. A(α) #24873 [1089]. [896, 2594, 333]. A∗ [2013]. A∗Ax = b [2369]. n A [1640, 566, 947, 1580, 1460]. A = a2 +1 − 0 n (3) [2450]. (A λB) [1414]. 0=1 [1242]. 1 [334]. α [824, 1580]. AN [1622]. A(#) [3439]. − 12 [3037, 2711]. 1 2 [1097]. 1:0 [3043]. 10 AX − XB = C [2195, 2006]. [838]. 11 [1311]. 2 AXD − BXC = E [1101]. B [2144, 1953, 2291, 2162, 3047, 886, 2551, 957, [2187, 1575, 1267, 1409, 1489, 1991, 1191, 2007, 2552, 1832, 949, 3024, 3219, 2194]. 2; 3 979, 1819, 1597, 1823, 1773]. β [824]. BN n − p − − [1490]. 2 1 [320]. 2 1 [100]. 2m 4 [1181]. BS [1773]. BSI [1446]. C0 [2906]. C1 [1105]. 3 [2119, 1953, 2531, 1351, 2551, 1292, [3202]. C2 [3108, 2422, 3000, 2036]. χ2 1793, 949, 1356, 2711, 2227, 570]. [30, 31]. Cln(θ); (n ≥ 2) [2929]. cos [228]. D 3; 000; 000; 000 [575, 637].
    [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]
  • Optimal Node Selection Algorithm for Parallel Access in Overlay Networks
    1 Optimal Node Selection Algorithm for Parallel Access in Overlay Networks Seung Chul Han and Ye Xia Computer and Information Science and Engineering Department University of Florida 301 CSE Building, PO Box 116120 Gainesville, FL 32611-6120 Email: {schan, yx1}@cise.ufl.edu Abstract In this paper, we investigate the issue of node selection for parallel access in overlay networks, which is a fundamental problem in nearly all recent content distribution systems, grid computing or other peer-to-peer applications. To achieve high performance and resilience to failures, a client can make connections with multiple servers simultaneously and receive different portions of the data from the servers in parallel. However, selecting the best set of servers from the set of all candidate nodes is not a straightforward task, and the obtained performance can vary dramatically depending on the selection result. In this paper, we present a node selection scheme in a hypercube-like overlay network that generates the optimal server set with respect to the worst-case link stress (WLS) criterion. The algorithm allows scaling to very large system because it is very efficient and does not require network measurement or collection of topology or routing information. It has performance advantages in a number of areas, particularly against the random selection scheme. First, it minimizes the level of congestion at the bottleneck link. This is equivalent to maximizing the achievable throughput. Second, it consumes less network resources in terms of the total number of links used and the total bandwidth usage. Third, it leads to low average round-trip time to selected servers, hence, allowing nearby nodes to exchange more data, an objective sought by many content distribution systems.
    [Show full text]
  • CS302 Final Exam, December 5, 2016 - James S
    CS302 Final Exam, December 5, 2016 - James S. Plank Question 1 For each of the following algorithms/activities, tell me its running time with big-O notation. Use the answer sheet, and simply circle the correct running time. If n is unspecified, assume the following: If a vector or string is involved, assume that n is the number of elements. If a graph is involved, assume that n is the number of nodes. If the number of edges is not specified, then assume that the graph has O(n2) edges. A: Sorting a vector of uniformly distributed random numbers with bucket sort. B: In a graph with exactly one cycle, determining if a given node is on the cycle, or not on the cycle. C: Determining the connected components of an undirected graph. D: Sorting a vector of uniformly distributed random numbers with insertion sort. E: Finding a minimum spanning tree of a graph using Prim's algorithm. F: Sorting a vector of uniformly distributed random numbers with quicksort (average case). G: Calculating Fib(n) using dynamic programming. H: Performing a topological sort on a directed acyclic graph. I: Finding a minimum spanning tree of a graph using Kruskal's algorithm. J: Finding the minimum cut of a graph, after you have found the network flow. K: Finding the first augmenting path in the Edmonds Karp implementation of network flow. L: Processing the residual graph in the Ford Fulkerson algorithm, once you have found an augmenting path. Question 2 Please answer the following statements as true or false. A: Kruskal's algorithm requires a starting node.
    [Show full text]
  • Dualheap Sort Algorithm: an Inherently Parallel Generalization of Heapsort
    Dualheap Sort Algorithm: An Inherently Parallel Generalization of Heapsort Greg Sepesi Eduneer, LLC [email protected] 2007 June 20 ABSTRACT The proposed dualheap sort algorithm employs the dualheap selection algorithm [3] to recursively partition A generalization of the heapsort algorithm is proposed. subheaps in half as shown in Figure 1-1. When the At the expense of about 50% more comparison and subheaps become too small to partition any more, the move operations for typical cases, the dualheap sort array is sorted. In the figure, the downward triangles algorithm offers several advantages over heapsort: represent the partitions with larger values, the upward improved cache performance, better performance if triangles represent the partitions with smaller values, the input happens to be already sorted, and easier and the arrow represents the direction of increasing parallel implementations. values and increasing heap indices, indicating that the subheaps with smaller values employ negative indices. 1. ALGORITHM OVERVIEW At the expense of about 50% more comparison and A heap is an array with elements regarded as nodes in move operations for the typical case, the dualheap sort algorithm offers significant improvements to heapsort’s a complete binary tree, where node j is the parent of small but important set of inefficiencies: nodes 2j and 2j+1, and where the value of each parent node is superior to the values of its children. This superiority of all the parent nodes is commonly called • When the input is already sorted, dualheap the heap condition. sort performs zero move operations and just NlogN comparison operations. • Heapsort is an elegant and popular sorting algorithm The dualheap sort has better cache by J.W.J.
    [Show full text]
  • Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ
    Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. ! Instructor: X. Zhang Acknowledgement • The set of slides have use materials from the following resources • Slides for textbook by Dr. Y. Chen from Shanghai Jiaotong Univ. • Slides from Dr. M. Nicolescu from UNR • Slides sets by Dr. K. Wayne from Princeton • which in turn have borrowed materials from other resources • Other online resources 2 Outline • Sorting problems and algorithms • Divide-and-conquer paradigm • Merge sort algorithm • Master Theorem • recursion tree • Median and Selection Problem • randomized algorithms • Quicksort algorithm • Lower bound of comparison based sorting 3 Sorting Problem • Problem: Given a list of n elements from a totally-ordered universe, rearrange them in ascending order. CS 477/677 - Lecture 1 4 Sorting applications • Straightforward applications: • organize an MP3 library • Display Google PageRank results • List RSS news items in reverse chronological order • Some problems become easier once elements are sorted • identify statistical outlier • binary search • remove duplicates • Less-obvious applications • convex hull • closest pair of points • interval scheduling/partitioning • minimum spanning tree algorithms • … 5 Classification of Sorting Algorithms • Use what operations? • Comparison based sorting: bubble sort, Selection sort, Insertion sort, Mergesort, Quicksort, Heapsort, … • Non-comparison based sort: counting sort, radix sort, bucket sort • Memory (space) requirement: • in place: require O(1), O(log n) memory • out of place:
    [Show full text]
  • Fundamental Data Structures Contents
    Fundamental Data Structures Contents 1 Introduction 1 1.1 Abstract data type ........................................... 1 1.1.1 Examples ........................................... 1 1.1.2 Introduction .......................................... 2 1.1.3 Defining an abstract data type ................................. 2 1.1.4 Advantages of abstract data typing .............................. 4 1.1.5 Typical operations ...................................... 4 1.1.6 Examples ........................................... 5 1.1.7 Implementation ........................................ 5 1.1.8 See also ............................................ 6 1.1.9 Notes ............................................. 6 1.1.10 References .......................................... 6 1.1.11 Further ............................................ 7 1.1.12 External links ......................................... 7 1.2 Data structure ............................................. 7 1.2.1 Overview ........................................... 7 1.2.2 Examples ........................................... 7 1.2.3 Language support ....................................... 8 1.2.4 See also ............................................ 8 1.2.5 References .......................................... 8 1.2.6 Further reading ........................................ 8 1.2.7 External links ......................................... 9 1.3 Analysis of algorithms ......................................... 9 1.3.1 Cost models ......................................... 9 1.3.2 Run-time analysis
    [Show full text]
  • 00 Fast K-Selection Algorithms for Graphics Processing Units
    00 Fast K-selection Algorithms for Graphics Processing Units TOLU ALABI, JEFFREY D. BLANCHARD, BRADLEY GORDON, and RUSSEL STEINBACH, Grinnell College Finding the kth largest value in a list of n values is a well-studied problem for which many algorithms have been proposed. A naive approach is to sort the list and then simply select the kth term in the sorted list. However, when the sorted list is not needed, this method has done quite a bit of unnecessary work. Although sorting can be accomplished efficiently when working with a graphics processing unit (GPU), this article proposes two GPU algorithms, radixSelect and bucketSelect, which are several times faster than sorting the vector. As the problem size grows so does the time savings of these algorithms with a sixfold speedup for float vectors larger than 224 and for double vectors larger than 220, ultimately reaching a 19.1 times speed-up for double vectors of length 228. Categories and Subject Descriptors: D.1.3 [Concurrent Programming]: Parallel programming;; F.2.2 [Non-numerical Algorithms and Problems]: Sorting and searching;; G.4 [Mathematical Software]: Parallel and vector implementations;; I.3.1 [Hardware Architecture]: Graphics Processors General Terms: Algorithms, Design, Experimentation, Performance Additional Key Words and Phrases: K-selection, Order Statistics, Multi-core, Graphics Processing Units, GPGPU, CUDA 1. INTRODUCTION The k-selection problem, a well studied problem in computer science, asks one to find the kth largest value in a list of n elements. This problem is often referred to as finding the kth order statistic. This task appears in numerous applications and our motivating example is a thresholding operation, where only the k largest values in a list are retained while the remaining entries are set to zero.
    [Show full text]
  • Introspective Sorting and Selection Algorithms
    Introsp ective Sorting and Selection Algorithms David R Musser Computer Science Department Rensselaer Polytechnic Institute Troy NY mussercsrpiedu Abstract Quicksort is the preferred inplace sorting algorithm in manycontexts since its average computing time on uniformly distributed inputs is N log N and it is in fact faster than most other sorting algorithms on most inputs Its drawback is that its worstcase time bound is N Previous attempts to protect against the worst case by improving the way quicksort cho oses pivot elements for partitioning have increased the average computing time to o muchone might as well use heapsort which has aN log N worstcase time b ound but is on the average to times slower than quicksort A similar dilemma exists with selection algorithms for nding the ith largest element based on partitioning This pap er describ es a simple solution to this dilemma limit the depth of partitioning and for subproblems that exceed the limit switch to another algorithm with a b etter worstcase bound Using heapsort as the stopp er yields a sorting algorithm that is just as fast as quicksort in the average case but also has an N log N worst case time bound For selection a hybrid of Hoares find algorithm which is linear on average but quadratic in the worst case and the BlumFloydPrattRivestTarjan algorithm is as fast as Hoares algorithm in practice yet has a linear worstcase time b ound Also discussed are issues of implementing the new algorithms as generic algorithms and accurately measuring their p erformance in the framework
    [Show full text]