




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Let L ={ a 1 , a 2 , …, a n } be a list of n numbers each consisting of exactly k digits. That is, each number is of the form d k d k - 1 … d 1 , where each d i is a digit between 0 and 9. In this problem, instead of applying induction on n , the number of objects, we use induction on k , the size of each integer.
If the numbers are first distributed into the lists by their least significant digit , then a very efficient algorithm results. Suppose that the numbers are sorted lexicographically according to their least k - 1 digits, i.e., digits d k - 1 , d k - 2 , …, d 1 . After sorting them on their k th digits, they will eventually be sorted.
Example: Sort A nondecreasingly. A[1…5]=7467 3275 6792 9134 1239
Input : A linked list of numbers L ={ a 1 , a 2 , …, an } and k , the number of digits. Output : L sorted in nondecreasing order.
Time Complexity: (n) Space Complexity: (n)