Putting Things in Order
Sort a messy pile by comparing two items at a time and swapping when the left one is bigger. That is how computers order lists too.
- Compare two numbers and say which is larger
- Swap two cards when they are in the wrong order
- Explain that sorting is repeating compare-and-swap until nothing moves
Finish first
Topic contents
Lesson 1 of 3
Compare two at a time
Spread four number cards on a table: 3, 1, 4, 2. You want smallest on the left. Look at the first pair: 3 and 1. Three is bigger, so swap them. Now it reads 1, 3, 4, 2.
Move one position right. Compare 3 and 4. Three is not bigger than four, so leave them. Compare 4 and 2. Swap. After one full pass, the biggest number often drifts toward the end.
Open the card sort lab and step through Four cards. Read each sentence aloud. The lab never jumps ahead; it shows every compare and every swap.
Card sort
Compare neighbouring cards and swap when the left is bigger, until the row is sorted.
Put the cards in order
Compare neighbours, swap when the left is biggerStart
These cards are out of order. Put them smallest to largest by comparing neighbours two at a time and swapping when the left card is bigger.
Lesson 2 of 3
Keep going until it stops
If you repeat passes until no swap happens, the cards end up sorted. Try the Backwards preset: 4, 3, 2, 1. Watch how many comparisons that takes.
Computers sort names for phone books, scores for leaderboards, and prices for shopping sites. The numbers are bigger, but the idea is the same: compare, maybe swap, repeat.
You do not need to remember the name of the method. You need the habit: check two, fix if wrong, repeat.
Lesson 3 of 3
You already know the hard part
Class 3 to 5 you learned sequences, loops, choices and now ordering. That is the skeleton of every program you will meet later.
In class 11 you will meet named sorts and Big-O notation. They will feel familiar because you already watched cards move one swap at a time.
Finish the path quiz, then show someone the robot lab and the card lab. Teaching it back is the best check that you understand it.
Practice
Work these out yourself
No answer key here on purpose: these are the questions worth thinking through before you move on. Open one and work it out.
0/3 attemptedAssessment
Check your understanding
Answer each question, then read the explanation. That is where the learning is.
Finished this topic?
0 of 3 lessons marked done. Marking the topic complete ticks the rest.
