Thread: Calculating mode

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    38

    Calculating mode

    Can ne1 tell me the algotithm to calculate the mode of an int list. The numbers are already sorted!

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    As long as you can be sure that your list is ordered this will work for unimodal data and will give one of the modes for multimodal data (I'm sure you can make it more genaral ).

    1) Start by saying that the mode is the first element of the list and that the mode count is one.

    2) While the current element is equal to the previous one step through the list incrementing the count

    2a) If the count is greater than for any other number, then the current number is the new mode.

    3) if the current number is different from the last one reset the count.

    4) Once you reach the end of the list you know the mode...
    DavT
    -----------------------------------------------

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. console mode and service mode
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-01-2008, 01:42 AM
  2. calculating the mode
    By bigggame in forum C Programming
    Replies: 10
    Last Post: 06-13-2006, 03:04 AM
  3. Shortening main
    By pdstatha in forum C Programming
    Replies: 1
    Last Post: 04-03-2002, 04:56 PM
  4. Showing the directory sturcture
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-26-2002, 04:46 PM
  5. free() usage
    By pdstatha in forum C Programming
    Replies: 5
    Last Post: 03-13-2002, 09:28 AM