Binary search needs a sorted list, but new star IDs arrive all jumbled. Rocket lays five ID cards on the table: 7, 3, 9, 1, 5.
"I will just shuffle them around until they look right," he says, sliding cards everywhere.
Raven stops his hand gently. "What do you notice about where the smallest card belongs?"
"At the very front," Rocket says. "So find the smallest first?"
Nova draws a glowing line after the first spot. "Here is a hint. Once a card is in place, you never touch it again."
| Pass | Smallest found | Cards after the pass |
|---|---|---|
| Start | 7, 3, 9, 1, 5 | |
| 1 | 1 | 1, 3, 9, 7, 5 (1 swapped with 7) |
| 2 | 3 | 1, 3, 9, 7, 5 (3 is already in place) |
| 3 | 5 | 1, 3, 5, 7, 9 (5 swapped with 9) |
| 4 | 7 | 1, 3, 5, 7, 9 (7 is already in place) |
Five cards took 4 passes. The last card did not need a pass, because it was the only one left.
Sort the cards 5, 1, 4, 2, 3 with selection sort. Pass 1 swaps 1 with 5, giving 1, 5, 4, 2, 3.
| Statement | True or false? |
|---|---|
| Pass 1 always finds the smallest card of all. | ? |
| Selection sort touches sorted cards again later. | ? |
| After pass 3, the cards are 1, 2, 3, 5, 4. | ? |
| Pass 4 swaps 4 and 5. | ? |
Great sorting! You found the smallest and moved it front, again and again. Tomorrow we count every comparison.