Huffman's greedy algorithm:
Create a leaf node for each character with its frequency.
Put all nodes in a min-heap (by frequency).
While heap has more than node:
- Extract two minimum frequency nodes.
- Create a new internal node with these as children.
- Insert the new node with frequency = sum.
The remaining node is the root. Edges to left are , to right are . A character's code is the path from root to leaf. Time: . Space: .