Skip to main content
Codepiko
TR
All activities

To save a PDF, choose "Save as PDF" as the destination in the print window.

Sorting algorithms: balance scale

The big idea

Many sorting algorithms work only by comparing two things at a time, just like weighing two boxes on a balance scale without seeing their weights. An algorithm’s speed is measured by how many comparisons it makes. Selection sort looks for the lightest of the remaining boxes in every round and weighs a lot. Quicksort picks a pivot and splits the boxes into a light pile and a heavy pile; it usually weighs far less.

Where do we meet it?

A shopping site sorts products by price, a game sorts its high-score table by points and a phone sorts contacts by name. When millions of things are sorted, the number of comparisons matters a lot: selection sort needs about 500 thousand comparisons to sort 1000 things, while quicksort needs about 14 thousand on average.

40 minutes in classFor teachers

  1. 5 minGetting attentionWhich bottle is heavier?Bring four bottles wrapped in paper, each with a different amount of water inside. A pupil holds two bottles at a time and says which one is heavier. Ask the class: “How few comparisons can find the heaviest?” Write the guesses on the board, then try it: 3 comparisons.
  2. 12 minLessonCard scalesPairs cut out and fold the cards on the sheet. One holds the cards; the other weighs by saying two letters and writes every weighing in the log. When the boxes are in order, they swap. Write on the board how many weighings each pair needed; the pair with the fewest explains how they thought.
  3. 15 minLessonSplit with a pivotBring six pupils to the front, each holding a weight card facing away. Choose one as the pivot. The others are compared with the pivot one by one; lighter ones walk to the left, heavier ones to the right. Do the same in each group and count the weighings. Compare with selection sort’s 15 weighings. Pairs do part three of the sheet; those who finish move on to the Balance Scale game.
  4. 8 minAssessmentHow many weighings?Ask the board: “How many weighings does it take to find the heaviest of 10 boxes?” Find the answer (9) together: each weighing rules out one box. Exit card: “Why does quicksort usually weigh less? Which pivot slows it down?”

Codepiko · Computer science: Sorting algorithms: balance scale

Sort without looking

Goal: Sort by comparing only two boxes at a time, without seeing the weights, and count the weighings.

Time: 30 min · You need: Scissors, pencil; for class play, a few same-looking bottles of different weights

Name:
Class:
Date:

1. Box cards

Cut out the cards and fold them on the dashed line: letter in front, weight behind. Your partner holds the cards; you do not look at the weights. Say two letters and your partner says which is heavier: one weighing.

  • Afold9 kg
  • Bfold4 kg
  • Cfold13 kg
  • Dfold2 kg
  • Efold7 kg
  • Ffold11 kg

2. Weighing log

Log every weighing: left box, right box, heavier one. Do not weigh what you already know: if A is heavier than B and B than C, then A is heavier than C. Finally, order the boxes from lightest to heaviest.

#Left panRight panHeavier
1
2
3
4
5
6
#Left panRight panHeavier
7
8
9
10
11
12

Lightest to heaviest:

Number of weighings:

3. Which weighs less?

Now the weights are known. Selection sort finds the lightest remaining box each round. Quicksort makes the first box the pivot, weighs every other box against it into a light or heavy pile, then sorts each pile the same way. How many weighings does each make?

  • A8 kg
  • B3 kg
  • C11 kg
  • D5 kg
  • E14 kg
  • F1 kg
MethodWeighings
Selection sort
Quicksort

codepiko.com