# Finding the median value, am I missing something?

If I'm not missing anything, please tell me. This is my understanding of the definition of a statistical mean:

Using the definition: The median is the middle value that separates the lower and higher halves of a number set.

And the small example: (2, 3, 3, 5, 8, 10, 11) Median = 5 (Because this is an odd number of data points, we have an actual middle data point).

And if we have an even number of data points we can just divide the number of data points by two, then add that numbered data point with the next data point, and divide that result by two to get the median, right?

So the simple rule might be if your data set has an odd number of data points, subtract 1, divide by 2, then add 1 back to find the median value. And if your data set has an even number of data points, divide the data set by 2, then add that data points value with the next data points value, divide by two, and that's the data sets median value. Am I wrong here?

In other words, if our data set contained: (3, 9, 22, 4, 73, 15) First, we would sort it numerically: (3, 4, 9, 15, 22, 73). Then we would take the two middle data points, add them together, and then divide them by two to get the median. Right? Median = $$\frac{9+15}{2} = 12$$

Given this, I don't understand the existence of more complex median algorithms to find the median. If I have a data set that contains 30 million salaries - and I mean EXACTLY 30 million - I would simply add data point number 15,000,000 with data point number 15,000,001, then divide the result by 2 and get the median salary. Right?

And if I had 30,873,713 salaries in my data set, data point number 15,436,856 + 1 would be the exact median, right?

• If you edit the question to tell us about the "more complex median algorithms" that concern you we may be able to help. Commented May 5 at 19:26
• I'm really not understanding your question. Are you asking about how to find the index of the data point that is the median? In any case, most software packages handle this pretty easily. Commented May 5 at 19:59
• I am literally asking if my understanding of what a "mean" is is correct. Commented May 5 at 20:10
• The index of the data point that is the median would point to the median value, right? Commented May 5 at 20:14
• "I am literally asking if my understanding of what a "mean" is is correct." I'll assume that is a typo and you meant "median". I'm pretty sure your understanding is completely correct. Commented May 5 at 20:20

You are right, but the problem is that sorting 30 million elements array is not efficient(not faster that $$O(nlog(n))$$. So median algorithms exist to find the median of an unsorted vector faster($$O(n)$$). Here is a simple example.