1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Formula for median of a set (sorted)

  1. Feb 4, 2014 #1
    Now i think i derived this correctly, but i'm not sure if it's correct, can anyone give me a confirmation?


    Where ##x## is the result of subtracting 1 from the observations and then dividing by 2.

    Then ##x+1=Median##

    Thank you :)

    Edit: Oops, this is the handicapped version of the better formula... figures
  2. jcsd
  3. Feb 6, 2014 #2
    If you're writing a method that returns the median of a sorted set of n numerical observations, I'm assuming they are all sorted in an array of size n. If so, you have to check whether the size of the array is an even or odd number. If even, return the arithmetic mean of the middle two observations; if odd, return the middle observation. This might look like:

    public double getMedian( data [] list )
    if( list.length % 2 == 0 )
    return ( list[ list.length / 2 ] + list[ ( list.length / 2 ) - 1 ] ) / 2.0;
    return list[ list.length / 2 ];
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: Formula for median of a set (sorted)
  1. Sorting Array (Replies: 6)

  2. Sorting technique (Replies: 4)

  3. Merge sort (Replies: 1)