Each project below is tailored to a specific algorithm and scientific question from Chapter 16, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.
Project 1 of 3 · v1-c16-p01Foundational · ~20 min
Run-Length Encoding (RLE) Compressor & Expansion Test
Boundary Condition: Digit characters inside raw text require tuple/binary framing so counts are not confused with data digits.
Common Mistake to Avoid: Encoding raw text containing numbers as flat "35" (is that three 5s or thirty-five?).
Interpreting Results: No lossless compressor works equally well on every input; algorithm choice depends on data structure.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 16 before testing the boundary case: Digit characters inside raw text require tuple/binary framing so counts are not confused with data digits.
Extension Challenge: Add an escape-run optimization that only RLE-encodes runs of length >= 3.
Reflection Question: Why does zipping an already-compressed ZIP or JPEG file usually make it slightly bigger?
Real-World Problem: Fixed 8-bit ASCII wastes bits by giving rare letters like Z the same length as common letters like E.
Scientific Question: How close does Huffman's greedy binary tree get to Claude Shannon's theoretical entropy limit H?
Objective: Build a Huffman tree from symbol frequencies, verify the prefix-free property, encode/decode bitstreams, and compare average bits/symbol against Shannon entropy.
Hypothesis to Test: Huffman's average code length L always satisfies H <= L < H + 1 bits per symbol.
Step-by-Step Implementation
Count character frequencies and create leaf nodes.
Repeatedly merge the two lowest-frequency nodes into a parent node until one root remains.
Traverse left=0, right=1 to assign prefix-free bitstrings and verify no code is a prefix of another.
Compare average bit length against H = -Σ p_i log2(p_i).
Expected Output: A gets 1-bit code (0); average length ≈ 2.00 bits/symbol vs. Shannon entropy H ≈ 1.96 bits/symbol (vs. 8 bits ASCII).
Test Cases: Single unique symbol ("AAAA") -> handle specially with 1-bit code "0"; Skewed text -> exact lossless round-trip.
Boundary Condition: An input with only 1 unique character produces a 1-node tree and must still assign a 1-bit code.
Common Mistake to Avoid: Forgetting that the decoder also needs the frequency table or canonical code lengths stored in the header.
Interpreting Results: Huffman coding is mathematically optimal among symbol-by-symbol prefix-free codes.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 16 before testing the boundary case: An input with only 1 unique character produces a 1-node tree and must still assign a 1-bit code.
Extension Challenge: Compare uniform distribution ("ABCDEFGH") vs. skewed distribution and confirm uniform yields 3.00 bits/symbol.
Reflection Question: How do LZ77 (Abraham Lempel & Jacob Ziv) and Huffman work together inside DEFLATE (ZIP and PNG)?