Thread: Generating the Mode of a Data Set

  1. #1
    Registered User
    Join Date
    Jun 2008
    Location
    Northern Va
    Posts
    18

    Wink Generating the Mode of a Data Set

    Hello,
    I'm working with a large data set and was wondering if there were some statistical shortcuts. I'm trying to compute the mode of a data set and can only think of an O(n^2) solution. Ordinarily, this wouldn't be too bad, but I feel like there might be something else that I could do. This is what I was thinking of trying:
    Code:
    int count=0,temp,mode=nums[0];
    for (i=0;i<setMax;i++)
        {
         temp =0;
         for(j=0;j<setMax;j++)
             if(nums[j]==nums[i]) temp++;
         if(temp>count)
            {
             temp=count;
             mode = nums[i];
             };
         };
    When I used the mode function in excel, there was a noticeable amount of time in between when I pressed enter and when the function returned something around 1.7 (approx .25sec). Since I have to compute the mode many times, I hope that I can optimize it without having to do something too complicated. Obviously, I could used a linked list with frequencies, but then other parts of my code would slow down unreasonably.

    Thanks for you help.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If your numbers are integers, you can do bucket sort (we just had this discussion, I think).

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603

  4. #4
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Just for curiosity. Thought this was cool

    http://vision.bc.edu/~dmartin/teachi...-html/all.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  5. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 13
    Last Post: 10-31-2002, 02:56 PM