Tags: Greedy
The code for A is 0, and no other code starts with 0; the code for T is 11, and no other code starts with 11; and so on. We call such a code a prefix-free code.
Use Priority Queue to determine which (node or subtree) is the next one to insert.
- Insert all node in priority queue
- Extract 2 minimum, make them two child of a subtree, insert them back to priority queue, mark as subtree.
- While still have node, goto 2