Do you understand what this question means
Find top log(n) or top sqt(n) values in an array of integers in less than linear time.
If you don’t, here is the question http://www.careercup.com/question?id=9337669.
Could you please help me in understanding this question and then may be get it solved. (Although once i understand i might get it solved too)
Thanks for your time.
Assuming the array is not sorted, This problem is
Omega(n), since you need to read all elements [finding max isOmega(n)problem in non-sorted array, and this problem is not easier then finding max]. So, there is no sublinear solution for it.There is
O(n)[linear] solution, using selection algorithm(*)This pseudo code is not correct if the array contain dupes, but trimming the dupes in a second step is fairly easy.