Lesson 6: Teach it

Capstone. A three-minute script, one diagram, a demo, and the questions learners will ask.

~20 minutes plus one real delivery. Builds on lessons 1 to 5.

The three-minute script

  1. Rule (20s). "Walk left to right. Compare neighbours. Bigger on the left? Swap. That walk is a pass."
  2. One pass live (60s). Five numbers on the board. Learners call swap or keep before you move. End: "the biggest is now at the end, and it always will be."
  3. Invariant (40s). "After k passes the last k slots are final. So n - 1 passes finish it: the last number has nowhere else to go."
  4. Cost (40s). Draw the triangle of dots. "Half a square: n²/2 comparisons. Ten times the data, a hundred times the work. That is why real sorts are n log n."
  5. Close (20s). "One flag makes sorted input cost one pass. It is stable because we only swap on strictly greater. It is a teaching sort, not a shipping sort."

The one diagram

Draw exactly this: a row of boxes, the last k shaded, an arrow riding the unshaded prefix left to right carrying "max". Label the shaded part "fixed after k passes". Everything in the script points at it.

The demo

Use this visualizer full-screen. Edit data-values to a learner's numbers; nothing else changes.

Backup: VisuAlgo with pseudocode highlighting.

Questions learners ask

QuestionAnswerLesson
Does it start over after a swap?No. It continues to the next pair.1
Why n - 1 passes and not n?After n - 1 slots are fixed the last value is forced.2
Why does the inner loop shrink?The fixed suffix never needs comparing again.2
Is sorted input fast?Only with the swapped flag: one pass, O(n).3
How slow, really?n(n - 1)/2 comparisons; 25,000x slower than merge sort at a million.4
Is it stable?Yes, because of strict >. Change to ≥ and it is not.5
What should I use instead?Library sort. For tiny inputs, insertion sort.5
Why teach it at all?Simplest sort with a real invariant and a real cost lesson.Astrachan

Rehearsal check

Record yourself once. Tick all five before you call it done.





Get real feedback (wisdom)

Post your script and diagram on CS Educators Stack Exchange and ask which step loses beginners. Post the TypeScript on r/algorithms for accuracy. Then deliver it to one real learner and tell your teaching agent what they asked; that becomes a learning record.

Primary source

Teaching the Bubble Sort Algorithm Using CS Unplugged Activities (ACM TOCE): documented learner misconceptions, so you see them coming.

Anything unclear? Ask your teaching agent - it wrote this lesson and can go deeper on any point.