Huffman exhibits optimal substructure.

**Proof:** Consider the optimal tree T for characters C.

- Let x and y be lowest frequency characters in C.
- Consider the optimal tree T' for C' = C - {x,y} {z}, where f(z) = f(x) + f(y).
- If there is a better tree for C', call it T'', then we could use T'' to build a better original tree by adding in x and y under z.
- The original tree T is optimal, so this is a contradiction.
- Thus T' is the optimal tree for C'.
- Huffman exhibits optimal substructure.

**Theorem 17.4**

Huffman produces optimal prefix codes.