Maggie HTTN
Case Study • Data Compression

Huffman Coding

Designing a structured learning experience for greedy tree construction, prefix-free code extraction, and compression reasoning.

Huffman coding can feel abstract when learners see only the final tree or finished bit strings. This module makes each greedy merge visible, helping learners connect local frequency choices to global code efficiency.

The project uses visualization, guided prediction, and step-by-step structural change to support understanding before implementation.

Project Scope

Curricular Target
Algorithms, Data Structures, or introductory Data Compression modules.
Delivery Model
Hybrid instructional module; adaptable for synchronous lecture or asynchronous self-study.
Learner Profile
Students learning greedy algorithms and tree-based representations for the first time.
Primary Objective
Enable students to explain why repeated minimum-frequency merges produce an optimal prefix-free code.

Core Learning Outcomes

  • Construct a Huffman tree step-by-step using the greedy merge rule.
  • Explain why the two smallest frequencies are merged first at each stage.
  • Derive binary codes from root-to-leaf paths in the completed tree.
  • Apply the resulting codes to encode and decode symbols correctly.

Learning Challenge

Learners often remember the procedure of “merge the two smallest” without understanding why that decision supports optimal compression. Static diagrams also tend to hide the iterative growth of the tree, making it harder to connect frequency, depth, and code length.

Design Strategy

Concrete Data Before Tree Structure
The lesson begins with a visible frequency list so learners can ground the algorithm in actual symbol data before abstraction appears.
Greedy Choice Through Repetition
Each merge highlights the two smallest values to reinforce the repeated decision rule rather than presenting it as a hidden mechanism.
Incremental Tree Growth
The tree is built step-by-step so learners can see how local merges accumulate into a final global structure.
Structure-to-Code Translation
Root-to-leaf traversal is shown explicitly so learners can connect the finished tree to actual binary strings.

Solution Design

The learning sequence was designed to make Huffman coding visually stable and conceptually transferable from frequency data to tree structure, then from tree structure to symbolic encoding and decoding.

1. Leaf Nodes From Raw Frequencies

The module starts by creating one leaf node for each character and its frequency. This keeps attention on the input set before any merge decisions occur.

2. Ascending Order Before Merging

Nodes are sorted by frequency so the greedy rule becomes visible. Learners can see why the smallest two elements are selected first rather than simply being told to trust the algorithm.

3. Controlled Iterative Merge Construction

Each merge follows the same visual pattern: select the two smallest nodes, combine them, display the summed parent, then reinsert the result into the ordered set. This consistency supports pattern recognition across multiple iterations.

4. Progressive Structural Growth

The tree is revealed as the cumulative result of repeated local decisions. Learners can observe how low-frequency symbols move deeper while larger combined weights remain available for later merges.

5. Code Extraction From Structure

Once the tree is complete, the visualization transitions to reading bit labels from root to leaf. This step externalizes how prefix-free codes come directly from the finished structure.

6. Encoding and Decoding as Transfer

Example words and bit strings are processed using the generated codes so learners can connect tree construction to practical use. This reinforces Huffman coding as a reversible system, not just a tree-building exercise.


Evaluation & Iteration:

Early feedback suggested that learners hesitated at two points: why the greedy choice leads to optimality, and how the final tree becomes actual bit strings.

The design was refined by strengthening merge-selection cues, keeping left/right bit labels visually consistent, and slowing the transition from tree structure to explicit code extraction.

Instructional Visualization

The animation highlights the two minimum-frequency nodes at each step, merges them into a parent node, reinserts the sum, and repeats until the final tree emerges.

Watch actively: pause, predict the next merge, and decide what new parent value will appear.

The completed tree is then used to derive prefix-free codes, encode a sample word, and decode a binary sequence back into symbols.

Guided Worksheet (Pause & Predict)

These worksheet prompts are aligned to the actual sequence shown in the animation. Pause at each stage, predict the next structural move, then continue to confirm or revise your reasoning.

Part 1 — Build the Initial Set
  • What is the first thing we should create from the frequency table: leaf nodes, internal nodes, or codes?
  • Why does each character begin as its own leaf node?
  • Which character has the smallest frequency, and which has the largest?
Part 2 — Sort Before Merging
  • After creating the leaf nodes, what should we do next?
  • Why must the nodes be sorted in ascending order before merging?
  • Using the given frequencies, what is the correct ascending order of the six symbols?
Part 3 — First Merge
  • Which two nodes should be merged first?
  • What parent frequency should be created from that merge?
  • Why are these two nodes chosen before all others?
Part 4 — Reinsert and Repeat
  • After creating the node with frequency 14, where should it be placed in the ordered list?
  • What are the next two smallest available values after reinsertion?
  • What new parent value is formed when they are merged?
Part 5 — Middle Stages of Tree Growth
  • Which two nodes combine to form 40?
  • Which two nodes combine to form 60?
  • Why is 34 merged with 26 before 40 and 26 are merged?
Part 6 — Final Merge
  • What are the last two remaining nodes before the tree is complete?
  • What is the value of the final root node?
  • What does that root value represent in relation to the original frequencies?
Part 7 — Read Codes From the Tree
  • How do we derive a code for a character from the finished tree?
  • Why do only leaf nodes receive final codes?
  • What is the code for one of the sample symbols shown in the final code table?
Part 8 — Encoding
  • To encode the word CAFE, which symbol should you translate first?
  • What code is assigned to C, and what code is assigned to A?
  • What final binary string do you get after concatenating the codes for C, A, F, and E?
Part 9 — Decoding
  • When decoding, why must you start at the root each time a character is completed?
  • How do you know when to stop reading bits for one character?
  • What word is produced by the decoding example shown at the end of the video?

Focus on the reasoning behind each merge and path, not just the final answers. The goal is to understand how local greedy choices build a valid global code.

Assessment Strategy

This module evaluates understanding through guided prediction, structure tracking, and application of the final codes to encoding and decoding tasks.

  • Formative assessment (during learning): Guided prompts help students identify the next greedy choice and justify why it is correct.
    • Which two frequencies should be merged next?
    • Why are these two values chosen before the others?
    • What parent value will be created by this merge?
  • Application assessment (structure + code): Students track how repeated merges change the tree and how bit labels convert structure into codes.
    • Which character becomes deeper in the tree after this merge?
    • How does the final path to a leaf become a binary code?
    • Why does a more frequent symbol usually receive a shorter code?
  • Summative assessment (after learning): A short exit check confirms whether students can independently construct and apply a Huffman code.
    • Why does merging the two smallest frequencies support optimal compression?
    • How do you know the final code is prefix-free?
    • How would you encode or decode a short word using the completed tree?

Assessment Activities

  • Prediction prompts before each merge event.
  • Ordered-list reconstruction after reinsertion steps.
  • Code-tracing exercises from root to leaf.
  • Encoding and decoding checks using the final code table.

Inclusive Design

  • Visible sorting and merge cues reduce cognitive search.
  • Consistent left/right bit labeling supports stable code reading.
  • Pacing control supports review at different processing speeds.
  • Guided worksheet prompts support different learning preferences.

Instructional Outcome

Learners can confidently construct a Huffman tree, derive prefix-free codes, and explain how repeated minimum-frequency merges support efficient compression.