Open the editor

Computer science · High school

Huffman Coding 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

Huffman coding compresses data by giving frequent symbols short codes and rare ones long codes. Students build a Huffman tree by joining the two rarest nodes again and again, read off the codes and count the bits saved.

The slides, one by one

1 Huffman coding

Short codes for common letters

Why should E get a shorter code than Z?

2 Join the two rarest, again and again

Counts: A 5, B 2, C 1, D 1

C + D, then B + 2, then A + 4

3 Common symbols get the shortest codes

Read the 0s and 1s from the top

No code starts another: prefix-free

4 Counting the bits saved

The message AAAAABBCD has 9 symbols. Compare a fixed 2-bit code with the Huffman codes A = 0, B = 10, C = 110, D = 111.

→ Bits = Σ count × code length

\text{Fixed: } 9 \times 2 = 18\ \text{bits}
\text{Huffman: } 5(1) + 2(2) + 1(3) + 1(3)
= 5 + 4 + 3 + 3 = 15\ \text{bits}
\text{Saving} = 3/18 \approx 17\%

15 bits instead of 18, about 17% smaller

5 Quick check

With A = 0, B = 10, C = 110 and D = 111, what does 100111 decode to?

  • BAD
  • BAC
  • ABD
  • DAB
Show the answer

BAD

Read from the left: 10 = B, 0 = A, 111 = D.

6 What to remember

Frequent symbols: short codes

Join the two smallest counts each time

Left 0, right 1: read the path

Prefix-free: decodes without gaps

Challenge: Why does Huffman coding save nothing when every symbol is equally common?

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 do you build a Huffman tree?

List the symbols with their counts, then repeatedly join the two smallest into a new node whose count is their sum, until one tree is left. Label left branches 0 and right branches 1; each symbol's path is its code.

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.