← Back to All Algorithms

📦 Huffman Coding

How It Works (Greedy)

  1. Create a leaf node for each character with its frequency
  2. Build a min-priority queue of all nodes
  3. Extract two nodes with minimum frequency
  4. Create new internal node with sum of frequencies
  5. Insert new node back into queue
  6. Repeat until one node remains (root)

Character Frequencies

Priority Queue

Click "Start" to build Huffman tree