GATE Computer ScienceEasyGATE CS (PYQ pattern)
Twelve symbols, all with the same frequency 1, are encoded with an optimal Huffman code. What is the total number of bits to encode one occurrence of each symbol?
- A. 44
- B. 48
- C. 36
- D. 40
Correct answer: A. 44
With equal weights Huffman builds an almost complete tree: since 8 < 12 ≤ 16, 2·(12 − 8) = 8 symbols get 4-bit codes and the other 4 get 3-bit codes: 8·4 + 4·3 = 44. Giving all 12 symbols ⌈log₂ 12⌉ = 4 bits gives 48.
More Algorithms questions
- In the hiring problem 10 candidates arrive in uniformly random order. The first 3 are only interviewed (never hired); from candidate 4 on…
- Karger's contraction algorithm is run on a connected multigraph with n = 8 vertices, but it stops when 4 super-vertices remain (instead of…
- Which of the following statements is/are correct? I. For metric TSP, doubling an MST and shortcutting gives a 2-approximation. II…
- A = [2, 5, 9, 14, 20, 27, 35, 41] and B = [1, 6, 8, 15, 22, 30, 33, 45, 50] are sorted. What is the 10th smallest element of the union of…
- How many non-empty contiguous subarrays of [3, 4, −7, 1, 3, 3, 1, −4, 2, 5, −3, 6] have sum exactly 7?
- How many pairs of positions i < j in the sorted array [1, 3, 4, 6, 7, 9, 11, 14, 15, 19] have a[i] + a[j] ≤ 20?