first sort the given array , you will get

1,1,1,1,2,2,2,3,3,3,3,3,4,4,5

now count frequency of each number and insert it into min heap.
each node contain 2 variable.
1) frequency
2) number

now do extract min operation.

and expand , for eg:-
for node 5
frequency = 0
number =5;
write 5 to the given array

for node 4
frequency = 2
number =4
write 4,4 to array.

for node 2
frequency = 3
number =2

write 2,2,2 to the given array...



On Sat, Dec 24, 2011 at 10:57 PM, Ankur Garg <ankurga...@gmail.com> wrote:

> how can one do frequency sort .
>
> Suppose we have an integer array like
>
> 1,2,3,1,2,3,1,1,2,3,4,4,3,5,3
>
> Then 1 is appearing 4 times
>           2 - 3
>           3- 5
>           4-2
>           5-1
>
> Then if we sort by frequency we shud have this as result
>
> 5,4,4,2,2,2,1,1,1,1,3,3,3,3,3
>
> How to do it
>
> --
> 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.
>

-- 
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