Huffman Coding

Codeword Encoding/Decoding

Fixed-Length Codes

Codeword Decoding

Uniquely Decodable Codes

Example 1

Example 2

Example 3

Example 4

Discussion on Instantaneous Codes

Definitions and Testing for Unique Decodability

Procedure to Test for Unique Decodability

  1. Examine all pairs of codewords: Identify if one codeword is a prefix of another.
  2. Check the dangling suffix: If the dangling suffix matches any original codeword, the code is not uniquely decodable. Otherwise, add the dangling suffix to an augmented list for further checks.
  3. Repeat the process: Continue until no new unique dangling suffixes can be added or a suffix matches an original codeword.

Examples

Example 5

Example 6

Example 7

Notes on Uniquely Decodable Codes

Huffman Encoding

A full implementation can be seen here

Example of Huffman Encoding

Consider a set of symbols R = {r1, r2, r3, r4, r5, r6} with the following probabilities of occurrence:

My Example Image

My Example Image

Draw Huffman trees

My Example Image

While the end-of-symbols-need-to-be-encoded is not reached:

Example:

Consider a set of symbols R = {r1, r2, r3, r4}

Design a Huffman code for these symbols and calculate the average bit rate per each symbol.

Average bit rate calculation:

Assigned Huffman Codes:

Average bit rate calculation:

Huffman Decoding

While the end-of-compressed-Huffman-data is not reached:

Example: