Data Structures & AlgorithmsHardGATE CS
Symbols occur with frequencies 24, 26, 33, 34, 35, 38. How many bits does an optimal (Huffman) prefix code need for the whole message, and how many would a fixed-length code need?
- A. 521 and 570
- B. 497 and 570
- C. 497 and 1140
- D. 473 and 570
Correct answer: B. 497 and 570
Total Huffman bits = sum of all merge costs (repeatedly merge the two smallest) = 497. A fixed-length code needs ⌈log₂6⌉ = 3 bits per symbol: 570.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A binary search tree holds exactly the keys 27, 34, 63, 64, 72, 73, 95, 99. Which ONE of the following can be its POSTORDER traversal?
- Five matrices have dimensions 5×5 , 5×5 , 5×15 , 15×4 , 4×3. What is the minimum number of scalar multiplications needed to compute their…
- The directed graph A→B (4), A→C (5), A→E (3), B→D (6), B→E (-3), C→E (7), D→C (1), E→D (2) has one negative edge but no negative cycle…
- Dijkstra's algorithm runs from A on the directed graph A→C (15), A→D (3), B→E (4), B→F (12), C→B (12), C→E (1), D→B (2), D→C (9), E→A…
- Heap sort (ascending) is run on [44, 9, 47, 27, 1, 46, 30, 10]: build a max-heap bottom-up, then repeatedly swap the root with the last…
- A binary search tree holds exactly the keys 17, 22, 27, 39, 40, 92, 97, 98. Which ONE of the following can be its POSTORDER traversal?