48. How does Huffman coding work?
HardGreedy algorithms
Technical
Show model answer
Count character frequencies, then repeatedly merge the two least frequent nodes (using a min-heap) into a new node whose weight is their sum. The resulting tree gives each character a prefix-free binary code, with frequent characters getting shorter codes; this is optimal among prefix codes.