Skip to content
Worked Examples · Example 7.2

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?

CBSENCERTSubjective· 3mImportance★★★★★
3% · 3/97 Questions
🔒 Locked · start free trial →

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

MeasureHow it is obtainedWhat it answers
Meanadd every value, divide by n"What is the arithmetic average?"
Mediansort, 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):

Position123456789
Height (cm)859090100102110110110115
Counting from the right987654321

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

StepActionResult
1Sort the data ascending85, 90, 90, 100, 102, 110, 110, 110, 115
2Count the values, n9
3n is odd → median position = (n + 1)/2position 5
4Read the value at position 5102 cm
5Cross-check by counting from the rightposition 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.