Given is an array of size n which was divided to n/k intervals of size k each. The values in each interval are bigger than the ones in the interval to its left and smaller than the ones in the interval to its right. I want to sort those values in the minimum time that I can.
The naive solution that I thought of is just to sort all the values in each interval which will “cost” O(k log k), for a total cost for all the n/k intervals of O(n log k). I wonder if there’s something more efficient.
Now I know that in each interval I have no more than log log k different values, I need to come up with a quicker algorithm. I’d love your help with this.
Thanks!
Here’s an extremely ugly answer:
The time used for 2,3 is O(K*logloglogK) since the search takes at most logloglogK (log on the loglogK elements) and repeated for K times. 4 use at most O(loglogK) time to walk through all the nodes with values. 5 takes O(K) time, similar to the Counting Sort. So the total time should be O(nlogloglogK).
Any question is welcomed since I am really sleepy and cannot guarantee that I am thinking straightly.