Question DSA-GRDY-0064
HardWhat is the output of this code?
import heapq
def huffman_cost(freq):
h = list(freq); heapq.heapify(h); cost = 0
while len(h) > 1:
a, b = heapq.heappop(h), heapq.heappop(h)
cost += a + b; heapq.heappush(h, a + b)
return cost
print(huffman_cost([5, 9, 12, 13, 16, 45]))
- A.
232
- B.
100
- C.
Sign up free to see the answer and a step-by-step explanation.