Skip to content

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.

Class 3 to 5beginner20 min3 lessons1 interactive lab
By the end you will be able to
  • 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

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.

Interactive lab

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 bigger
3
1
4
2
0comparisons0swaps
1 / 14

Start

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.

Continue

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.

Continue

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.

Continue

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 attempted

Assessment

Check your understanding

Answer each question, then read the explanation. That is where the learning is.

0/4
  1. Question 1: When should you swap two neighbouring cards?
    Question 1 / 4

    When should you swap two neighbouring cards?

    Select an option first
  2. Question 2: How do you know sorting is finished in the lab?
    Question 2 / 4

    How do you know sorting is finished in the lab?

    Select an option first
  3. Question 3: Starting with 3, 1, 4, 2, what is the first swap?
    Question 3 / 4

    Starting with 3, 1, 4, 2, what is the first swap?

    Select an option first
  4. Question 4: Why do computers sort data?
    Question 4 / 4

    Why do computers sort data?

    Select an option first
4 of 4 questions left.

Finished this topic?

0 of 3 lessons marked done. Marking the topic complete ticks the rest.