Finding the median value of an array?

Assuming the array x is sorted and is of length n:

If n is odd then the median is x[(n-1)/2].
If n is even than the median is ( x[n/2] + x[(n/2)-1] ) / 2.

Leave a Comment