Integer Sorting in O ( N //Spl Root/Log Log N/ ) Expected Time and Linear Space

Total Page:16

File Type:pdf, Size:1020Kb

Integer Sorting in O ( N //Spl Root/Log Log N/ ) Expected Time and Linear Space p (n log log n) Integer Sorting in O Expected Time and Linear Space Yijie Han Mikkel Thorup School of Interdisciplinary Computing and Engineering AT&T Labs— Research University of Missouri at Kansas City Shannon Laboratory 5100 Rockhill Road 180 Park Avenue Kansas City, MO 64110 Florham Park, NJ 07932 [email protected] [email protected] http://welcome.to/yijiehan Abstract of the input integers. The assumption that each integer fits in a machine word implies that integers can be operated on We present a randomized algorithm sorting n integers with single instructions. A similar assumption is made for p (n log log n) O (n log n) in O expected time and linear space. This comparison based sorting in that an time bound (n log log n) improves the previous O bound by Anderson et requires constant time comparisons. However, for integer al. from STOC’95. sorting, besides comparisons, we can use all the other in- As an immediate consequence, if the integers are structions available on integers in standard imperative pro- p O (n log log U ) bounded by U , we can sort them in gramming languages such as C [26]. It is important that the expected time. This is the first improvement over the word-size W is finite, for otherwise, we can sort in linear (n log log U ) O bound obtained with van Emde Boas’ data time by a clever coding of a huge vector-processor dealing structure from FOCS’75. with n input integers at the time [30, 27]. At the heart of our construction, is a technical determin- Concretely, Fredman and Willard [17] showed that we n (n log n= log log n) istic lemma of independent interest; namely, that we split can sort deterministically in O time and p p n (n log n) integers into subsets of size at most in linear time and linear space and randomized in O expected time space. This also implies improved bounds for deterministic and linear space. The randomized bound can also be string sorting and integer sorting without multiplication. achieved deterministically using space unbounded in terms "W 2 "> 0 of n (of the form for constant ), but here we focus on bounds with space bounded in terms of n. 1 Introduction In 1995, Andersson et al. [5] improved Fredman and p (n log n) Willard’s O expected time for integer sorting to (n log log n) Integer sorting has always been an important task in con- O expected time. Both of these bounds use lin- nection with the digital computer. A classic example is ear space. A similar result was found independently by Han the folklore algorithm radix sort, which according to Knuth and Shen [23]. [28] is referenced as far back as in 1929 by Comrie in a The above mentioned bounds are the best unrestricted document describing punched-card equipment [14]. bounds in the sense that no better bounds are known even if (log n) Whereas radix sort works in linear time for O -bit besides the randomization, we have unlimited space and are integers, it was not until 1990 that Fredman and Willard [17] free to define our own operations on words. n log n) beat the ( comparison-based sorting lower-bound The above results have provided great inspiration for for the case of arbitrary single word integers. The word-size many researchers, trying to improve them in various ways. W log n W is determined by the processor. We assume For example, there has been work on avoiding randomiza- so that we can address the different integers, but in princi- tion [4, 21, 22, 31, 33] and there has been work on avoiding n ple, W can be arbitrarily large compared with . An equiv- multiplication [3, 6, 36]. Also there has been lots of work alent formulation of our assumptions is that we only assume on more dynamic versions of the problem such as priority constant time operations on integers polynomial in the sum queues [13, 18, 31, 33, 34] and searching [3, 4, 8, 9]. (n log log n) Supported in part by University of Missouri Faculty Research Grant The O algorithm of Andersson et al. from K211942 1995 [5] is very simple, and the fact that it has sustained so Proceedings of the 43 rd Annual IEEE Symposium on Foundations of Computer Science (FOCS’02) 0272-5428/02 $17.00 © 2002 IEEE much interest has lead many researchers to think that this Theorem 3 improves a corresponding refinement of Kirk- (n log n) could be the complexity for integer sorting, like O patrick and Reich [27] of van Emde Boas’ bound of log U ) (n log is the complexity of comparison based sorting. O expected time. log n (n log log n) However, in this paper, we improve the O The following simple lemma states that it suffices for us p (n log log n) expected time to O expected time: to prove Theorem 3: Lemma 4 Theorem 3 implies Theorem 1 and Corollary 2. Theorem 1 There is a randomized algorithm sorting n in- p (n log log n) tegers, each stored in one word, in O ex- pected time and linear space. Proof: Trivially Theorem 3 implies the weaker Corol- lary 2. However, Andersson et al. [5] have shown that we We leave open the problems of getting a corresponding de- 3 (log n) can sort in linear expected time if W , and other- terministic algorithm and avoid the use of multiplication. U log W 3 log log n wise, log log . We note that the dynamic aspects are already pretty settled, for the complexity of dynamic searching is known to be p log n= log log n) ( [8, 9], and priority queues have once 1.1 Other domains and for all been reduced to sorting [35]. (log n) Since integers of O bits can be sorted in linear time using radix sort, we get the following immediate con- In this paper, we generally assume that our integers to be sequence of Theorem 1: sorted each fit in one word, where a word is the maximal unit that we can operate on with a single instruction. In this subsection, we briefly discuss implications of this case to U Corollary 2 We can sort n integers of size at most in p many other domains. (n log log U ) O expected time. First, consider the case of lexicographically ordered (n log log U ) This is the first improvement over the O bound strings of words. Andersson and Nilsson [7] have presented obtained with van Emde Boas’ data structure from 1975 an optimal randomized reduction from this case to that of (n log log n) [37]. Indeed, the O sorting algorithm of An- integers fitting in single words. Applying their reduction to dersson et al. [5] combines van Emde Boas’ data structure Theorem 1, we get with the packed merging of Albers and Hagerup [2] so as to Corollary 5 We can sort n variable-length strings dis- p (n log log U ) U match the O bound for large values of . O (n log log n + N ) tributed over N words in expected p (log log U ) We note here that the general O bound of (n log log n + L) time. In fact, we can get down to O ex- van Emde Boas [37] has been improved in the context P L = ` ` i pected time where i and is the length of the of static search structures. More precisely, Beame and i distinguishing prefix of string i, that is, the smallest prefix Fich [9] have shown that one can preprocess a set of of string i distinguishing it from all the other strings, or the n integers in polynomial time and space so that given length of string i if it is a duplicate. any x, one can search the largest stored integer below O (log log U= log log log U ) x in time. However, due to We note here that any algorithm sorting the strings will have the polynomial construction time, this improvement does to read the distinguishing prefixes, and since it takes an in- not help with sorting. Beame and Fich [9] combine (L) struction to read each word, it follows that an additive O their result with Andersson’s exponential search trees from is necessary. [4], giving a dynamic search structure with an amor- One may instead be interested in variable length (log log U log log n= log log log U ) tized update time of O . multiple-word integers where integers with more words are This dynamic search structure could be used for sort- considered bigger. However, by prefixing each integer with (n log log U log log n= log log log U ) ing in O time, but this its length, we reduce this case to lexicographic string sort- (n log n) is never better than the best of O time and ing. (n log log U ) O time. Thus, from the perspective of sorting, p In our presentation, we think of all our integers as un- (n log log U ) our O bound constitutes the first improve- signed non-negative integers. However, the standard repre- (n log log U ) ment over the O bound derived from van Emde sentation of signed integers is such that if we flip the sign- Boas’ data structure from 1975 [37]. bit, we can sort them as unsigned integers, and then flip We will, in fact, prove the following refinement of Corol- the sign-bit back again. Floating points numbers are even lary 2: easier, for the IEEE 754 floating-point standard [25] is de- signed so that the ordering of floating point numbers can Theorem 3 There is a randomized algorithm sorting n be deduced by perceiving their representations as multiple W < 2 word integers, each of size at most U in q word integers.
Recommended publications
  • 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]
  • 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]
  • 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]
  • Lecture 1 — 24 January 2017 1 Overview 2 Administrivia 3 The
    CS 224: Advanced Algorithms Spring 2017 Lecture 1 | 24 January 2017 Prof. Jelani Nelson Scribe: Jerry Ma 1 Overview We introduce the word RAM model of computation, which features fixed-size storage blocks (\words") similar to modern integer data types. We also introduce the predecessor problem and demonstrate solutions to the problem that are faster than optimal comparison-based methods. 2 Administrivia • Personnel: Jelani Nelson (instructor) and Tom Morgan (TF) • Course site: people.seas.harvard.edu/~cs224 • Course staff email: [email protected] • Prerequisites: CS 124/125 and probability. • Coursework: lecture scribing, problem sets, and a final project. Students will also assist in grading problem sets. No coding. • Topics will include those from CS 124/125 at a deeper level of exposition, as well as entirely new topics. 3 The Predecessor Problem In the predecessor, we wish to maintain a ordered set S = fX1;X2; :::; Xng subject to the prede- cessor query: pred(z) = maxfx 2 Sjx < zg Usually, we do this by representing S in a data structure. In the static predecessor problem, S does not change between pred queries. In the dynamic predecessor problem, S may change through the operations: insert(z): S S [ fzg del(z): S S n fzg For the static predecessor problem, a good solution is to store S as a sorted array. pred can then be implemented via binary search. This requires Θ(n) space, Θ(log n) runtime for pred, and Θ(n log n) preprocessing time. 1 For the dynamic predecessor problem, we can maintain S in a balanced binary search tree, or BBST (e.g.
    [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]
  • On the Adaptiveness of Quicksort
    On the Adaptiveness of Quicksort Gerth Stølting Brodal∗;y Rolf Fagerbergz;x Gabriel Moruz∗ Abstract by Quicksort for a sequence of n elements is essentially Quicksort was first introduced in 1961 by Hoare. Many 2n ln n ≈ 1:4n log2 n [10]. Many variants and analysis variants have been developed, the best of which are of the algorithm have later been given, including [1, 12, among the fastest generic sorting algorithms available, 19, 20, 21]. In practice, tuned versions of Quicksort as testified by the choice of Quicksort as the default have turned out to be very competitive, and are used as sorting algorithm in most programming libraries. Some standard sorting algorithms in many software libraries, sorting algorithms are adaptive, i.e. they have a com- e.g. C glibc, C++ STL-library, Java JDK, and the .NET plexity analysis which is better for inputs which are Framework. nearly sorted, according to some specified measure of A sorting algorithm is called adaptive with respect presortedness. Quicksort is not among these, as it uses to some measure of presortedness if, for some given Ω(n log n) comparisons even when the input is already input size, the running time of the algorithm is provably sorted. However, in this paper we demonstrate em- better for inputs with low value of the measure. Perhaps pirically that the actual running time of Quicksort is the most well-known measure is Inv, the number of adaptive with respect to the presortedness measure Inv. inversions (i.e. pairs of elements that are in the wrong Differences close to a factor of two are observed be- order) in the input.
    [Show full text]
  • On Data Structures and Memory Models
    2006:24 DOCTORAL T H E SI S On Data Structures and Memory Models Johan Karlsson Luleå University of Technology Department of Computer Science and Electrical Engineering 2006:24|: 402-544|: - -- 06 ⁄24 -- On Data Structures and Memory Models by Johan Karlsson Department of Computer Science and Electrical Engineering Lule˚a University of Technology SE-971 87 Lule˚a, Sweden May 2006 Supervisor Andrej Brodnik, Ph.D., Lule˚a University of Technology, Sweden Abstract In this thesis we study the limitations of data structures and how they can be overcome through careful consideration of the used memory models. The word RAM model represents the memory as a finite set of registers consisting of a constant number of unique bits. From a hardware point of view it is not necessary to arrange the memory as in the word RAM memory model. However, it is the arrangement used in computer hardware today. Registers may in fact share bits, or overlap their bytes, as in the RAM with Byte Overlap (RAMBO) model. This actually means that a physical bit can appear in several registers or even in several positions within one regis- ter. The RAMBO model of computation gives us a huge variety of memory topologies/models depending on the appearance sets of the bits. We show that it is feasible to implement, in hardware, other memory models than the word RAM memory model. We do this by implementing a RAMBO variant on a memory board for the PC100 memory bus. When alternative memory models are allowed, it is possible to solve a number of problems more efficiently than under the word RAM memory model.
    [Show full text]
  • Optimizing Integer Sorting in O(N Log Log N) Expected Time in Linear Space
    Optimizing Integer Sorting in 푂(푛 푙표푔 푙표푔 푛) Expected Time in Linear Space Ajit Singh Dr. Deepak Garg M. E. (Computer Science and Engineering) Asst. Prof. Department of computer Science and Engineering, Department of Computer Science and Engineering, Thapar University, Patiala Thapar University, Patiala [email protected] [email protected] Abstract-The traditional algorithms for integer space. The table-1 shows the comparative analysis sorting give a bound of 푶(풏 풍풐품 풏) expected of various traditional algorithms: time without randomization and 푶(풏) with randomization. Recent researches have Table-1: Complexity Comparison optimized lower bound for deterministic Name Best Average Worst Memory algorithms for integer sorting [4, 5, 7]. We Insertion Sort 푂(푛) 푂(푛2) 푂(푛2) 푂(1) present a fast deterministic algorithm for Shell Sort 푂(푛) 퐷푒푝푒푛푑푠 푂(푛 푙표푔푛 2) 푂(푛) integer sorting in linear space. The algorithm Binary tree 푂(푛) 푂(푛푙표푔푛) 푂(푛푙표푔푛) 푂(푛) discussed in this paper sorts 풏 integers in the sort range {ퟎ, ퟏ, ퟐ … 풎 − ퟏ} in linear space in Selection sort 푂(푛2) 푂(푛2) 푂(푛2) 푂(1) 푶(풏 풍풐품 풍풐품 풏) expected time. This improves Heap sort 푂(푛푙표푔푛) 푂(푛푙표푔푛) 푂(푛푙표푔푛) 푂(1) the traditional deterministic algorithms. The Bubble sort 푂 푛2 푂(푛2) 푂(푛2) 푂(1) algorithm can be compared with the result of Merge sort 푂(푛푙표푔푛) 푂(푛푙표푔푛) 푂(푛푙표푔푛) Depends Andersson, Hagerup, Nilson and Raman which Quick sort 푂(푛푙표푔푛) 푂(푛푙표푔푛) 푂(푛2) 푂(log 푛) sorts n integers in 푶(풏 풍풐품 풍풐품 풏) expected time Randomized but uses 푶(풎ᵋ ) space [2, 14].
    [Show full text]
  • Sorting in Linear Time?
    Sorting in Linear Time? ¡ ¢ Arne Andersson Torben Hagerup Stefan Nilsson Rajeev Raman Abstract integers in the range ¥b¦¨¦c¤2 d in linear time via bucket sort- ing, thereby demonstrating that the comparison-based lower We show that a unit-cost RAM with a word length of £ bits bound can be meaningless in the context of integer sorting. ¥§¦¨¦ © ¤ ¤ can sort ¤ integers in the range in Integer sorting is not an exotic special case, but in fact time, for arbitrary £ ¤ , a signi®cant improvement is one of the sorting problems most frequently encountered. $¤ over the bound of !¤#" achieved by the fusion trees Aside from the ubiquity of integers in algorithms of all kinds, of Fredman and Willard. Provided that £%%&'(¤*)*+-, , for we note that all objects manipulated by a conventional com- some ®xed .0/1¥ , the sorting can even be accomplished in puter are represented internally by bit patterns that are inter- linear expected time with a randomized algorithm. preted as integers by the built-in arithmetic instructions. For Both of our algorithms parallelize without loss on a unit- most basic data types, the numerical ordering of the repre- cost PRAM with a word length of £ bits. The ®rst one yields senting integers induces a natural ordering on the objects rep- 2¤ ¤ an algorithm that uses 23 $¤ time and op- resented; e.g., if an integer represents a character string in the erations on a deterministic CRCW PRAM. The second one natural way, the induced ordering is the lexicographic order- yields an algorithm that uses 3(4¤ expected time and ing among character strings.
    [Show full text]
  • Predecessor Search
    Predecessor Search GONZALO NAVARRO and JAVIEL ROJAS-LEDESMA, Millennium Institute for Foundational Research on Data (IMFD), Department of Computer Science, University of Chile, Santiago, Chile. The predecessor problem is a key component of the fundamental sorting-and-searching core of algorithmic problems. While binary search is the optimal solution in the comparison model, more realistic machine models on integer sets open the door to a rich universe of data structures, algorithms, and lower bounds. In this article we review the evolution of the solutions to the predecessor problem, focusing on the important algorithmic ideas, from the famous data structure of van Emde Boas to the optimal results of Patrascu and Thorup. We also consider lower bounds, variants and special cases, as well as the remaining open questions. CCS Concepts: • Theory of computation → Predecessor queries; Sorting and searching. Additional Key Words and Phrases: Integer data structures, integer sorting, RAM model, cell-probe model ACM Reference Format: Gonzalo Navarro and Javiel Rojas-Ledesma. 2019. Predecessor Search. ACM Comput. Surv. 0, 0, Article 0 ( 2019), 37 pages. https://doi.org/0 1 INTRODUCTION Assume we have a set - of = keys from a universe * with a total order. In the predecessor problem, one is given a query element @ 2 * , and is asked to find the maximum ? 2 - such that ? ≤ @ (the predecessor of @). This is an extension of the more basic membership problem, which only aims to find whether @ 2 -. Both are fundamental algorithmic problems that compose the “sorting and searching” core, which lies at the base of virtually every other area and application in Computer Science (e.g., see [7, 22, 37, 58, 59, 65, 75]).
    [Show full text]
  • Inproved Parallel Integer Sorting Without Concurrent Writing
    Information and Computation IC2632 information and computation 136, 2551 (1997) article no. IC972632 Improved Parallel Integer Sorting without Concurrent Writing* Susanne Albers-, and Torben Hagerup- Max-Planck-Institut fur Informatik, D-66123 Saarbrucken, Germany We show that n integers in the range 1, ..., n can be sorted stably on an EREW PRAM using O(t) time and O(n(- log n log log n+(log n)2Ât)) operations, for arbitrary given tlog n log log n, and on a CREW PRAM using O(t) time and O(n(- log n+log nÂ2tÂlog n)) operations, for arbitrary given tlog n. In addition, we are able to sort n arbitrary integers on a randomized CREW PRAM within the same resource bounds with high probability. In each case our algorithm is a factor of almost 3(- log n) closer to optimality than all previous algorithms for the stated problem in the stated model, and our third result matches the operation count of the best previous sequential algorithm. We also show that n integers in the range 1, ..., m can be sorted in O((log n)2) time with O(n) operations on an EREW PRAM using a nonstandard word length of O(log n log log n log m) bits, thereby greatly improving the upper bound on the word length necessary to sort integers with a linear timeprocessor product, even sequentially. Our algorithms were inspired by, and in one case directly use, the fusion trees of Fredman and Willard. ] 1997 Academic Press 1. INTRODUCTION A parallel algorithm is judged primarily by its speed and its efficiency.
    [Show full text]
  • UPPER BOUNDS for SORTING INTEGERS on RANDOM ACCESS MACHINES by David Kirkpatrick* Stefan Reisch** Technical Report 81-12*** September, 1981
    UPPER BOUNDS FOR SORTING INTEGERS ON RANDOM ACCESS MACHINES by David Kirkpatrick* Stefan Reisch** Technical Report 81-12*** September, 1981 * Department of Computer Science, University of British Columbia, Vancouver, B.C., Canada ** Fakultat fur Mathematik, Universitat Bielefeld, Federal Republic of Germany *** This work was supported in part by the Natural Sciences and Engineering Research Council of Canada, grant A3583. ., Abstract Two models of Random Access Machines suitable for sorting integers are presented. Our main results show that i) a RAM with addition, sub­ traction, multiplication, and integer division can sort n integers in the range [0,2cn] in O(n loge+ n) steps; ii) a RAM with addition, subtraction, and left and right shifts can sort any n integers in linear time; iii) a RAM with addition, subtraction, and left and right shifts can sort n integers in the range [O,nc] in O(n loge+ n) steps, where all intermediate results are bounded in value by the largest input. 1. Introduction The general problem of sorting is one of the most fundamental land well studied) problems in computer science. For the most general formulation of the problem it is natural to restrict one's attention to comparison-based algorithms. In this setting, it is well-known that O(n log n) operations (comparisons) are necessary and sufficient to sort an arbitrary n-tuple. It is also well-known that if an n-tuple consists entirely of integers in the range [O,n-1] (or, in fact, any range of size O(n)), then it can be sorted in O(n) operations by a RAM.
    [Show full text]