🃏 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

Algorithm
Cards
Start

Compares: 0Swaps: 0

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

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):

Sources

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

Last reviewed: November 2026