fpr the nos with same frequency , the one having lower value shud come first

For ex

3,1,1,3,1,3,2

Here 1 should come first
so
2,1,1,1,3,3,3



On Sun, Dec 25, 2011 at 11:18 AM, top coder <topcode...@gmail.com> wrote:

> What about the case of the numbers having same frequency?
> Which one should come first?
>
> On Dec 24, 11:18 pm, atul anand <atul.87fri...@gmail.com> wrote:
> > 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.- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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