Thread: What is the mathematical forumula for finding the median of a odd number of values

  1. #1
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Question What is the mathematical forumula for finding the median of a odd number of values

    Sorry if this is too basic a question to ask here, but thought I'd ask it anyway.
    What is the mathematical formula for finding the median (i.e. the number in dead center) in an odd number of values? You can't divide the sum by 2, because that will give you one less than the center and a half. Do I just add an half after dividing by 2, or is there a better way?

    I tried Googling already, but couldn't find the answer.

    EDIT: Yeah, the above seems to work...
    Last edited by Programmer_P; 04-07-2011 at 03:07 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I tried Googling already, but couldn't find the answer.
    Lies!

    Seriously, the first result had the answer for about a dozen different variations.

    Soma

  3. #3
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by phantomotap View Post
    Lies!

    Seriously, the first result had the answer for about a dozen different variations.

    Soma
    forumla for median of odd number - Google Search

    The first couple of results didnt look like it had it, so I didn't go over them that deeply. But checking again, I see a couple of them did, but I missed that before. So its (x+1) / 2, where x is the total number of values. Oh well...
    Last edited by Programmer_P; 04-07-2011 at 03:29 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    There is no "formula" for it. Sort the list of values, then take the middle one.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by brewbuck View Post
    There is no "formula" for it. Sort the list of values, then take the middle one.
    Right. And if I recall correctly, to find the median of an even number of values you take the mean of the two adjacent values.

  6. #6
    Registered User
    Join Date
    Jul 2010
    Location
    Oklahoma
    Posts
    107
    For reference, the (arithmetic) mean of two numbers xi and xj is

    Code:
       (xi + xj)/2
    Best Regards
    Kept the text books....
    Went interdisciplinary after college....
    Still looking for a real job since 2005....

    During the interim, I may be reached at ELance, vWorker, FreeLancer, oDesk and WyzAnt.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  2. Replies: 4
    Last Post: 03-09-2002, 01:22 PM
  3. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM
  4. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM