GATE Computer ScienceEasyGATE CS (PYQ pattern)
A BST on 31 keys is perfectly balanced (all 5 levels full). Searching for each of the 31 keys with equal probability, what is the average number of key comparisons for a successful search (one comparison per node on the path, including the node holding the key)?
- A. 3.87 (120/31)
- B. 5.00
- C. 4.00
- D. 4.16 (129/31)
Correct answer: D. 4.16 (129/31)
Level d has 2^d nodes needing d + 1 comparisons: (1*1 + 2*2 + 4*3 + 8*4 + 16*5)/31 = 129/31, about 4.16.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Keys 1 to 5 are inserted into an empty BST in a uniformly random order of the 120 possible orders. In how many of the orders does key 3…
- Iterative postorder uses two stacks: push the root on S1; repeat: pop x from S1, push x on S2, push x's left child then its right child on…
- struct N { int v; int next; }; struct N a[6] = {{10,3},{20,5},{30,-1},{40,1},{50,2},{60,4}}; int i = 0, s = 0, k = 1; while (i != -1) { s…
- How many structurally distinct binary search trees on keys 1..7 have key 4 at the root and height exactly 3 (a single node has height 0)?
- char s = "abracadabra"; int c[26] = {0}, i; for (i = 0; s[i]; i++) c[s[i] - 'a']++; int best = 0; for (i = 1; i < 26; i++) if (c[i] (i +…
- For n = 7 distinct keys, what is the maximum number of swaps that the bottom-up (Floyd) build-heap for a max-heap can perform, over all…