- Published on
The Algorithm Design Manual (3rd) Exercise Solution 'E4-36'
Table of Contents
Introduction
This series is my solutions for algorithm exercises in'The Algorithm Design Manual' 3rd edition.
It's my solutions, not model answers, so if you find some mistakes or more sophisticated solutions, please post in comment area below.
Repository
Exercise 4-36
Question
Assume that the array only has numbers from but that at most log log n of these numbers ever appear. Devise an algorithm that sorts A in substantially less than .
Solution
First, we count the occurence of each number using hash table. Since the amount of the numbers existing in the array is considerably small, the procedure can be considered to take time.
Then, we sort those numbers and arrange them by the number of their occurrences. This takes time.
So the overall time complexity is .