CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    720

    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
  •  





Click Here to Expand Forum to Full Width

Featured