It can be done without sorting. Take the first element as pivot
element. Calculate its position using Partition algorithm.
If its new index is K, then on left side are top K  integers. If index>K,
apply algo on left side Else apply algo on right side.

Best Case: O(1)
Worst Case: O(n^2)

But there are very less chances of worst case. It is when the list is
already sorted.

On Thu, May 5, 2011 at 1:06 AM, amit <amitjaspal...@gmail.com> wrote:

> Hi ,
>
> We are give a list of integers now our task is to find the top K
> integers in the list based on frequency.
>
> Apart from sorting the data can there be any other algorithm?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Gaurav Aggarwal
SCJP

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to