Source Coding Visualizer

ECE 420 · Wireless Communications · NC State University

Background: Source coding compresses data by exploiting redundancy. Huffman coding exploits known symbol probabilities: it builds an optimal prefix-free code (no codeword is a prefix of another, so codewords can be decoded unambiguously as they arrive) by repeatedly merging the two least-likely symbols/groups into a binary tree, giving shorter codewords to more frequent symbols and achieving an expected length within one bit of the source entropy H(X) (the average information content of X, in bits/symbol). Lempel-Ziv (LZ) coding takes a different, universal approach that needs no prior knowledge of the statistics — it builds its "dictionary" adaptively from the data itself as it is processed, with LZ77 referencing a sliding window of recently-seen text and LZ78 growing an explicit phrase dictionary.

Description of This Web Application: Switch between Huffman and Lempel-Ziv modes. In Huffman mode, edit each symbol's probability and watch the priority-queue merges build the Huffman tree step by step, then inspect the resulting codebook and encode your own sample text to see the compression ratio. In Lempel-Ziv mode, choose LZ77 or LZ78, type or pick a preset input string, and step through the tokenization process one match at a time, watching the search buffer/dictionary, the matched text, and the emitted token at each step. You will come away understanding how probability-driven and dictionary-based compression differ, why Huffman coding approaches the entropy limit, and how LZ methods find redundancy without ever being told the source statistics.

Algorithm

Symbol Probabilities

Encode Sample Text

Legend

Algorithm Steps 1 / 1
Priority Queue (lowest probability first)
Encoding Result
Huffman Tree (Final)blue=0, green=1
Codebook