Stage 1 · Code
Greedy Algorithms
Huffman Coding
Optimal prefix codes with priority queue.
Prefix Codes
Prefix code: no code is prefix of another. Enables unambiguous decoding without delimiters. Binary tree: left=0, right=1. Leaves = symbols. Code = path from root. Optimal prefix code minimizes weighted path length (sum of freq × code length).
Huffman Algorithm
Greedy: combine two lowest frequency nodes into parent with sum frequency. Repeat until one tree remains. Use min-heap for O(n log n).
Implementation
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.