CH231A-Homework 7 Sorting in Linear Time and Radix Sort Solved
Problem 7.1 Sorting in Linear Time (a) Implement the algorithm for Counting Sort and then use it to sort the sequence < 9,1,6,7,6,2,1 .
(b) Implement the algorithm for Bucket Sort and then use it to sort the sequence < 0.9,0.1,0.6,0.7,0.6,0.3,0.1 .
(c) Given n integers in the range 0 to k, design and write down an algorithm (only pseudocode) with pre-processing time Θ(n+k) for building auxiliary storage, which counts in O(1) how many of the integers fall into the interval [a,b].
(d) Given a sequence of n English words of length k, implement an algorithm that sorts them alphabetically in Θ(n). Let k and n be flexible, i.e., automatically determined when reading the input sequence. You can consider k to behave like a constant in comparison with n. Example sequence of words to sort:
Algorithms and Data Structures Course: CH-231-A Jacobs University Bremen Dr. Kinga Lipskoch March 16th, 2020 (e) Given any input sequence of length n, determine the worst-case time complexity for Bucket Sort. Give an example of a worst-case scenario and the prove corresponding the complexity.
(f) Given n 2D points that are uniformly randomly distributed within the unit circle, design and write down an algorithm (only pseudocode) that sorts in linear time the points by increasing Euclidean distance to the circle’s origin. Write also a pseudocode function for the computation of the Euclidean distance between two 2D points.
Problem 7.2 Radix Sort Consider Hollerith’s original version of the Radix Sort, i.e., a Radix Sort that starts with the most significant bit and propagates iteratively to the least significant bit (instead of vice versa).
(a) Implement Hollerith’s original version of the Radix Sort.
(b) Determine and prove the asymptotic time complexity and the asymptotic storage space required for your implementation.
(c) Write down the pseudocode for an algorithm which sorts n integers in the range 0 to n3− 1 in O(n) time.