Back to problems

Huffman Tree Construction

Algorithm · Google · Medium

Requirements Given a mapping from each symbol to its occurrence count. Return a Huffman tree, or an equivalent mapping of symbols to prefix codes. Examples {"m": 3, "n": 6, "o": 8, "p": 11, "q": 14, "r": 38} — a valid Huffman tree places r immediately below the root. For example, the merge totals can be 9, 17, 25, 42, and finally 80, so r is paired only in the final merge. Symbols and counts in, one symbol code line out (symbols in alphabetical order): Notes In an L6 onsite…

Checking your access…