Q.Consider the previous data of height of students used in calculation of mean value. In order to compute the median, the first step is to sort data in ascending or descending order. We have sorted the height data in ascending order as [85,90,90,100,102,110,110,110,115]. Since there are 9 values (an odd number), what is the median of this data?
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The median is a positional statistic: sort the data, then take the middle value. For the nine heights [85, 90, 90, 100, 102, 110, 110, 110, 115], n = 9 is odd, so the median is the value at position (9 + 1)/2 = 5 → 102 cm. Exactly four heights lie below it and four above it.
Concept understanding — mean vs median
| Measure | How it is obtained | What it answers |
|---|---|---|
| Mean | add every value, divide by n | "What is the arithmetic average?" |
| Median | sort, then take the middle value | "What is the central value — the one that splits the data in half?" |
The mean uses the magnitude of every observation, so a single extreme value drags it. The median uses only the ordering, so it is resistant to outliers. This is why sorting is not an optional first step — it is the definition. Until the data is ordered, "the middle value" has no meaning.
If n is odd: median = value at position (n + 1) / 2 of the sorted data.
If n is even: median = mean of the values at positions n/2 and n/2 + 1.
Applying it to the height data
Sorted heights (ascending):
| Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| Height (cm) | 85 | 90 | 90 | 100 | 102 | 110 | 110 | 110 | 115 |
| Counting from the right | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
n = 9, which is odd, so:
median position = (9 + 1) / 2 = 5 → median = 102 cm
Counting from the left the 5th value is 102; counting from the right the 5th value is also 102. That symmetry is the proof that the value really is central: the four heights 85, 90, 90, 100 lie below it and the four heights 110, 110, 110, 115 lie above it.
Program
def mean(data):
return sum(data) / len(data)
def median(data):
values = sorted(data) # step 1 - ORDER the data
n = len(values)
if n % 2 == 1: # odd count -> single middle value
return values[n // 2] # index (n+1)/2 in 1-based = n//2 in 0-based
else: # even count -> average of the two middles
return (values[n // 2 - 1] + values[n // 2]) / 2
def mode(data):
return max(set(data), key=data.count)
heights = [110, 90, 100, 102, 110, 85, 90, 115, 110] # unsorted, as collected
print('Data :', heights)
print('Sorted data :', sorted(heights))
print('Number of values (n):', len(heights))
print('Mean : %.2f cm' % mean(heights))
print('Median : %d cm' % median(heights))
print('Mode : %d cm' % mode(heights))
Output
Data : [110, 90, 100, 102, 110, 85, 90, 115, 110]
Sorted data : [85, 90, 90, 100, 102, 110, 110, 110, 115]
Number of values (n): 9
Mean : 101.33 cm
Median : 102 cm
Mode : 110 cm
Step-by-step working of the median
| Step | Action | Result |
|---|---|---|
| 1 | Sort the data ascending | 85, 90, 90, 100, 102, 110, 110, 110, 115 |
| 2 | Count the values, n | 9 |
| 3 | n is odd → median position = (n + 1)/2 | position 5 |
| 4 | Read the value at position 5 | 102 cm |
| 5 | Cross-check by counting from the right | position 5 from the right = 102 cm ✓ |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.