GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Seven keys have search probabilities (in percent, in sorted key order) 18, 6, 22, 14, 4, 20, 16 and only successful searches occur. The root has depth 1. The expected number of comparisons in an optimal binary search tree is:
- A. 2.46
- B. 1.22
- C. 2.22
- D. 2.31
Correct answer: C. 2.22
The DP cost[i][j] = Σp + min over roots of the two sub-costs gives 222 for percent probabilities, i.e. 2.22 comparisons. The perfectly balanced tree costs 2.46, and counting depth from the root as 0 would give 1.22.
More Algorithms questions
- The egg-drop puzzle: a building has 100 floors, and you have 3 identical eggs. An egg that is dropped from a floor at or above the…
- A building has 100 floors and you have 2 identical eggs; an egg breaks when dropped from the critical floor or above, and a broken egg…
- Floyd–Warshall is run on a 5-vertex directed graph with weight matrix (rows are sources, ∞ = no edge): row1: [0, 6, ∞, 3, ∞]; row2: [∞, 0…
- Six jobs have (processing time, weight): (4,3), (2,5), (7,2), (3,6), (5,4), (1,1). A single machine runs them one at a time without gaps…
- How many non-empty subsets of {3, 5, 6, 7, 9, 11, 13, 14} have an element sum divisible by 10?
- A cyclic binary string of length 12 is written around a circle, so position 12 is followed by position 1. How many of the 2¹² strings…