Open the editor

Computer science · High school

Bubble Sort Slides

Free animated slides, ready to teach: 6 slides where every step appears on a click and the diagrams move. Play them right here, present them full screen, or copy them into your account to edit.

A real Tracé deck playing in your browser. No account needed.

What the lesson covers

Bubble sort walks along a list swapping neighbours that are in the wrong order, so the largest value bubbles to the end each pass. Students trace a list pass by pass, read the code and count comparisons in the worst case.

The slides, one by one

1 Bubble sort

Swap neighbours until sorted

How would you sort a hand of cards one swap at a time?

2 Each pass bubbles the largest to the end

Compare neighbours, swap if out of order

Pass 3 makes no swaps: sorted

3 One pass compares every pair of neighbours

Pass 1 on 5 1 4 2 8

4 comparisons for 5 items

4 Comparisons in the worst case

A list of 6 items is in reverse order. How many comparisons does bubble sort make?

→ Passes of 5, 4, 3, 2 and 1 comparisons

5 + 4 + 3 + 2 + 1
= \dfrac{6 \times 5}{2}
= 15

15 comparisons

5 Quick check

In the worst case, how many comparisons does bubble sort make on 10 items?

  • 45
  • 100
  • 10
  • 90
Show the answer

45

n(n − 1)/2 = 10 × 9 ÷ 2 = 45.

6 What to remember

Compare neighbours and swap

Each pass fixes the largest at the end

\begin{aligned}&\textsf{Worst case }n(n-1)/2\\ &\textsf{comparisons}\end{aligned}
O(n^2)\textsf{: slow for big lists}

Challenge: How many comparisons does it make on a list that is already sorted?

Every slide is built click by click: text, formulas and pictures come in one step at a time, so the class follows the reasoning instead of reading ahead. Graphs with sliders can be dragged live while you present.

Make your own version with AIChange the level, the numbers or the language: type the topic and get a new deck that moves in about 30 seconds. Free, no account needed.

Questions teachers ask

How many comparisons does bubble sort make?

In the worst case n(n − 1)/2: (n − 1) on the first pass, one fewer each pass after. Ten items need up to 45 comparisons, so bubble sort is O(n²).

Are these slides really free?

Yes. Watch them on this page or present them full screen with no account. Making your own copy to edit is free too.

Can I change the slides before my lesson?

Yes. Press "Make my own copy" and the deck becomes one of your projects in the Tracé editor, where you can change the text, the numbers, the colours or the order of the clicks.

Do they work on a classroom projector or an interactive whiteboard?

Yes. They run in the browser on any laptop, so anything that shows your screen works. Press the right arrow or click to go to the next step.