G2: Huffman Codes

San Skulrattanakulchai

October 26, 2018

File Compression

Encoding

Problem 1

Problem 2

Optimum Merge Trees

The general merging problem

Example

Problem 3

Problem 4

Greedy algorithm for merge patterns

Correctness

Huffman algorithm

Example

Implementation and Running Time

  1. For efficiency we implement Huffman algorithm iteratively rather than recursively.
  2. Instead of maintaining the items and the combined items as a sorted list as in the figure, we maintain them in a priority queue.

Pseudocode