|
-
June 16th, 2010, 04:40 PM
#1
The most frequent element in a list (the mode)
I'd be thankful if someone enlighten me how to solve this problem in most efficient manner both in terms of speed and memory consumption.
Example: [4,5,6,7,12,6,8,9,4,6,8,4,97,4] the answer is 4, the only solution that occured to me is to hold counters in a hash table and pick the maximum element. However, there could some circumstances where this could be inefficient, so I wonder if some straightforward method is available.
Thanks beforehand and regards.
Last edited by AvDav; June 16th, 2010 at 04:42 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|