since we have to visit each value at least once we have to do at least O(n) steps so there cant be a solution in time less than o(n) but if the range of the values is limited we can use another array to count the number of occurrences of each value and the complexity would be: o(n) time o(max of the values) space
On Tue, May 25, 2010 at 5:20 PM, Raj N <[email protected]> wrote: > Hi, > Can anyone tell me what is the most efficient algo to find the mode. > Is it sorting and the then finding the max occurrence or can it be > done in time less than O(n) ? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
