Huffman |
Document last modified: |
| c | m | n | o | p | q | r | s | t |
| f(c) | 3 | 5 | 9 | 4 | 2 | 7 | 6 | 8 |
Huffman (C) -- pre: C is the characters that comprise the alphabet -- post: return the root of the optimal encoding tree n ← |C| Q ← C -- insert all the elements of C into Q, using the frequency as the priority for i ← 1 to n-1 do z ← a new tree node x ← Extract-Minimum (Q) y ← Extract-Minimum (Q) left[ z ] ← x right[ z ] ← y f[z] ← f[x] + f[y] Insert (Q, z) return Extract-Minimum (Q) -- the root of the encoding tree |