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
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 pan | Right pan | Heavier |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 |
| # | Left pan | Right pan | Heavier |
|---|---|---|---|
| 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
| Method | Weighings |
|---|---|
| Selection sort | |
| Quicksort |
codepiko.com