Comparing and sorting values
Order numerical values by magnitude and use comparison operators correctly.
Prerequisites
Everyday explanation
Sorting means arranging data. Smallest first: 3, 7, 12, 25. Or largest first: 25, 12, 7, 3.
The operator < means “is less than” and > “is greater than”. Think of the symbol as a crocodile’s mouth: it opens towards the largest value. 3 < 7. 25 > 12.
Systems sort constantly: customer lists, salaries, search results. An AI model sorts its probabilities: most likely first.
Interactive
Sort like a computer: Take five values in a row. Compare only two values at a time and swap them if they are in the wrong order. Move from left to right, repeating until no swaps occur.
5 2 8 1 → 2 5 8 1 → 2 5 1 8 → 2 1 5 8 → 1 2 5 8.
Count the number of swaps. This is called bubble sort and is a fundamental algorithm.
Mastery means
- Order five values in ascending order
- Use the operators < and > correctly
Sign in to do the exercises and build your mastery up.
Sources
- CS Unplugged (CC BY-SA 4.0) — CC BY-SA 4.0