Please make sure you adhere to the policies on academic honesty.
Describe a simple method for sorting S in O(n) time. (Hint: Can you break the keys into components which can be viewed lexicographically?)
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}.
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?