Skip to content
Exit presentation

Computational Thinking Basics

Sorting is an algorithm too

Five number cards are in no order: 4, 1, 5, 2, 3. Write the exact steps to sort them.

Loading lab…

Sorting is an algorithm too. To sort is to put cards in order, smallest first.

Cards: 4, 1, 5, 2, 3.
Step 1 of 3
  1. Cards: 4, 1, 5, 2, 3.
  2. Compare the first two: 4 and 1.
  3. 4 is bigger — swap. Now: 1, 4, 5, 2, 3.

Compare two neighbours. Neighbours are two cards side by side. Swap them if the left one is bigger.

Then move to the next pair. Do this along the whole row.

  • 4 and 5: keep. Now: 1, 4, 5, 2, 3.
  • 5 and 2: swap. Now: 1, 4, 2, 5, 3.
  • 5 and 3: swap. Now: 1, 4, 2, 3, 5.

The row is not sorted yet. So do the whole row again. Stop when a whole row has no swap.

Jump to lesson

This track

  1. 0 Start here
  2. 1 Split the big job
  3. 2 Spot the repeat
  4. 3 Algorithm = exact steps, in order
  5. 4 Follow the steps exactly
  6. 5 Test the tricky case
  7. 6 Sorting is an algorithm too
  8. 7 The big picture
  9. 8 Track quiz

Other tracks