← Quiz: Rooted Trees and Huffman Coding: all 10 questions
Quiz: Rooted Trees and Huffman Coding · Question 10 of 10
What does this print? (code)
What does this print?
import heapq
heap = [5, 2, 2, 1, 1]
heapq.heapify(heap)
total = 0
while len(heap) > 1:
s = heapq.heappop(heap) + heapq.heappop(heap)
total += s
heapq.heappush(heap, s)
print(total)
- A.11
- B.33
- C.23
- D.21
Answer & explanation
Correct answer: 23
These are the abracadabra frequencies; the internal weights 2 + 4 + 6 + 11 add up to 23 bits.
Can you get the rest right without peeking?
Take the timed Quiz: Rooted Trees and Huffman Coding quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →