Homework Assignment

Radix Sort

Contents:

  • Overview
  • Practice Problems
  • Problems to be Submitted
  • Extra Credit

  • Overview

    Topic: Radix Sort
    Related Reading: A General discussion of sorting methods is contained in Ch. 5.4, Ch. 7.1.2, Ch. 7.2.3, Ch. 7.3.4, Ch. 10.1 and Ch. 10.3-10.6 of the text. Radix sort in particular is discussed in Ch. 10.5.
    Due:

    Please make sure you adhere to the policies on academic honesty.


    Practice Problems

  • Reinforcement Exercise R-10.14
  • Creativity Exercise C-10.12

  • Problems to be Submitted (20 points)

    1. (5 points)
      Suppose we are given a sequence S of n keys, each of which is an integer in the range [0, n2-1]. A standard use of bucket sort in this setting would result in an O(n2) running time.

      Describe a simple method for sorting S in O(n) time. (Hint: Can you break the keys into components which can be viewed lexicographically?)

    2. (15 points)
      Let S1, S2, ... Sk be k different sequences, where all sequences contain only integer keys within the range [0,N-1], for some parameter N>1. Let ni denote the length of sequence Si for 1 <= i <= k, and let n = Σ1 <= i <= k ni denote the sum of the lengths.

      Our goal is to devise an efficient way to have each of the sequences individually sorted, yet while not combining any of the sequences together. Perhaps we can make this more clear with an example. If the input is,
      S1 = {5,8,3,12,9,7},
      S2 = {9,7,11,2},
      S3 = {5,12,14,11,7}, and
      S4 = {4,0,2,9,12,6},
      then parameters values are k=4, N=15, and n=21
      (as n = n1 + n2 + n3 + n4 = 6 + 4 + 5 + 6 = 21)

      In this example, the desired output would be:
      S1 = {3,5,7,8,9,12},
      S2 = {2,7,9,11},
      S3 = {5,7,11,12,14}, and
      S4 = {0,2,4,6,9,12}.

      1. A simple approach is to separately call bucket-sort on each individual sequence. Give a brief argument explaining that the combined time used for all of these calls is at most O(k(N+n)).

      2. If you are more careful in analyzing the above approach, you should be able to show that it uses at most O(kN+n) overall time. Prove such a bound. Hint: Consider precise bounds for each call to bucket-sort.

      3. As it happens, there is a more efficient approach. You are to design and describe a method for solving the problem which requires using O(k+N+n) time overall, and you are to justify the running time claim.

        Hint: Rather than making a separate call to sort each sequence, devise a way to throw all elements, from all sequences into one big pile which can be sorted. Of course, if you use the original value of each item as the key, the items from different sequences will get interspersed. Can you define a new "key" in a way so that a sort of the entire group will help in preparing the desired output?


    Extra Credit (2 points)

    Creativity Exercise C-10.22 of the text.


    Last modified: 7 November 2002