🃏 Sorting Algorithms for Kids
Watch bubble, selection and insertion sort step by step · Be the computer · Race them on the same cards · Grades 3–8
A computer cannot see all the cards at once. It compares two numbers at a time and follows its rules. You be the computer: answer each question the way the algorithm would. The page counts every compare and swap.
All three algorithms get exactly the same cards. Each tick, every algorithm does one step: one compare or one swap. Which one needs the fewest steps? Try all three starting orders.
What Is a Sorting Algorithm?
An algorithm is a set of step-by-step rules for doing a job. A sorting algorithm puts things in order, such as numbers from smallest to biggest. Computers sort all the time: a list of songs by name, a game's high scores, or files by date. Different algorithms reach the same sorted answer in different ways, and some take far fewer steps than others on the same cards.
In this game, one step is either one compare (looking at two cards to see which is bigger) or one swap (two cards trading places). The counters add them up so you can compare the algorithms fairly.
Bubble sort
Compare the first two cards. If the left one is bigger, swap them. Move one place right and do it again, all the way to the end. The biggest card has now moved to the last place. Start again from the front, stopping before the cards already in place. If a whole trip has no swaps, stop: everything is sorted.
Selection sort
Look through all the unsorted cards, keeping track of the smallest one you have seen. At the end, swap that smallest card into the first unsorted place. Repeat for the next place. Selection sort makes very few swaps, but it always does the same number of compares, even when the cards start in order.
Insertion sort
Keep a sorted group at the front. Take the next card and compare it with the card on its left. If the left card is bigger, swap them and compare again. Stop when the left card is smaller, or the card reaches the front. It is like sliding a new card into the right place in a hand of playing cards.
What the race shows
Try the race with each starting order and look at the step counts. With nearly sorted cards, bubble sort and insertion sort finish quickly because they notice there is little to do, while selection sort still checks every pair it needs to find each smallest card. With backwards cards every algorithm has the most work to do. There is no single best algorithm for every case. Choosing one depends on what the data looks like.
For Parents and Teachers
- Unplugged first. Give six students number cards and have the class call out bubble sort instructions: “Compare Ana and Ben. Swap!” Count compares and swaps on the board, then check the count with the Watch tab.
- Be the computer. This tab asks one question for every compare. Students must follow the algorithm's rule, not their own idea of where a card belongs. Selection sort is the trickiest: the question is always about the smallest card so far.
- Predict the race. Before each race, have students predict which algorithm will win on mixed-up, nearly sorted and backwards cards, then explain the result.
- Older students. Ask them to count compares for selection sort with 6, 8 and 10 cards and find the pattern (15, 28, 45). It is the sum 5+4+3+2+1 and so on.
Completion code
Finishing a round of Be the computer shows a completion code with the number of decisions answered right the first time out of the total (activity ID CSR). Check codes on the Score Checker. Nothing is saved or sent anywhere.
Standards
This page supports these CSTA K–12 Computer Science Standards (2017):
- 1A-AP-08: “Model daily processes by creating and following algorithms (sets of step-by-step instructions) to complete tasks.” (Be the computer)
- 1B-AP-08: “Compare and refine multiple algorithms for the same task and determine which is the most appropriate.” (Race)
- 2-AP-10: “Use flowcharts and/or pseudocode to address complex problems as algorithms.” (Write the three algorithms above as pseudocode.)
Sources
- Computer Science Teachers Association: CSTA K–12 Computer Science Standards (2017) progression chart
FAQ
Which sorting algorithm is the fastest?
It depends on the cards. In the race, insertion sort and bubble sort finish quickly on nearly sorted cards, while selection sort always makes the same number of compares. Selection sort never makes more swaps than the other two. Run the race on all three starting orders to see the difference.
What counts as a step?
Every compare of two cards and every swap of two cards counts as one step. Remembering the smallest card so far and marking cards as finished are not counted, because they do not move or test any cards.
Why does bubble sort sometimes stop early?
Bubble sort watches for a whole trip along the row with no swaps. If that happens, every pair of neighbors is already in order, so the whole row is sorted and it can stop.
How does the Be the computer score work?
Each compare asks one question. You get a point when your first answer matches what the algorithm would do. A wrong answer explains the rule and lets you try again. The completion code holds your first-try score and the number of questions.
Keep Exploring
- Robot Maze: block coding puzzles with loops and if-checks.
- Turtle Draw: code drawings with forward, turn and repeat.
- Unplugged Coding: more algorithm games with no screen.
- Binary Numbers: how computers store numbers.
- Beat Maker: build a drum loop step by step.
- Coding and Computers: all the coding games and lessons.
Last reviewed: November 2026