GATE Computer ScienceHardGATE CS (PYQ pattern)
A text uses 8 symbols with frequencies 5, 9, 12, 13, 16, 45, 3 and 7. If a Huffman code is built, the total number of bits needed for the whole text (sum of frequency × code length) is:
- A. 330
- B. 284
- C. 272
- D. 301
Correct answer: B. 284
Huffman merging costs: 3+5 = 8, 7+8 = 15, 9+12 = 21, 13+15 = 28, 16+21 = 37, 28+37 = 65, 45+65 = 110; the sum of all merged weights is 8+15+21+28+37+65+110 = 284. A fixed 3-bit code would need 330.
More Algorithms questions
- A 0/1 knapsack has capacity 50 and items given as (value, weight): (60, 10), (100, 20), (120, 30), (75, 25). The maximum total value is:
- Which of the following statements are correct? (I) 2-SAT can be solved in polynomial time. (II) Subset-sum has a pseudo-polynomial…
- An AVL tree is a binary search tree in which the heights of the two subtrees of every node differ by at most 1. Taking the height of a…
- A B-tree has minimum degree t = 3 (every node other than the root holds between t − 1 and 2t − 1 keys; the root holds at least 1 key) and…
- A DAG has vertices 1 to 8 and edges 1→3, 2→3, 3→4, 3→5, 2→6, 6→5, 4→7, 5→7, 8→6, 1→8. How many different topological orderings does it have?
- A directed graph on vertices 0 to 11 has edges 0→1, 1→2, 2→0, 2→3, 3→4, 4→3, 5→3, 5→6, 6→7, 7→6, 8→9, 9→10, 10→8, 10→5, 11→3. What is the…