Huffman’s algorithm builds a Huffman tree bottom-up, and in every iteration it merges the two trees that have the smallest sums of corresponding symbol frequencies.

Pseudocode

  • Input: a nonnegative frequency $p_a$ for each symbol $a$ of an alphabet $\Sigma$.
  • Output: the Huffman tree with minimum average leaf depth, representing the prefix-free binary code with minimum average encoding length.

Last updated 09 May 2025, 23:43 +0500 . history