Data Structures & AlgorithmsHardProduct-company placement
Symbols occur with frequencies 7, 19, 20, 25, 26, 39. How many bits does an optimal (Huffman) prefix code need for the whole message, and how many would a fixed-length code need?
- A. 350 and 408
- B. 343 and 816
- C. 343 and 408
- D. 336 and 408
Correct answer: C. 343 and 408
Total Huffman bits = sum of all merge costs (repeatedly merge the two smallest) = 343. A fixed-length code needs ⌈log₂6⌉ = 3 bits per symbol: 408.
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 rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 2, 4, 15, 18, 19, 23, 24, 29. What is…
- What is the maximum flow from S to T in the network with directed capacities A→C (13), A→T (8), B→C (10), B→T (10), C→T (3), S→B (4), S→C…
- Keys 66, 49, 54, 41, 65, 58, 22, 18, 42, 47 are inserted into an empty AVL tree (giving preorder 54, 41, 22, 18, 47, 42, 49, 65, 58, 66)…
- An undirected connected graph has edges A–D, A–F, A–G, B–C, B–F, B–H, B–I, C–D, C–H, D–F, E–I. How many articulation points (cut vertices)…
- A min-heap holds 31 distinct keys in a 0-indexed array (a full tree with 5 levels). At how many different indices can the 4th-smallest key…
- In the grid 11111 / 11112 / 11121 / 11111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…