Mental Model
Huffman encoding builds a tree to assign shorter codes to frequent letters and longer codes to rare letters, saving space.
Analogy: Imagine you have a box of colored pencils where you use some colors a lot and others rarely. You label the common colors with short names and rare colors with longer names to write faster.
Characters with frequencies:
a:5 b:9 c:12 d:13 e:16 f:45
Initial nodes:
[a:5] [b:9] [c:12] [d:13] [e:16] [f:45]
Tree after combining two smallest:
*
/ \
[a:5] [b:9]
Remaining nodes:
[*:14] [c:12] [d:13] [e:16] [f:45]