GATE Computer ScienceEasyGATE CS (PYQ pattern)
Binary search on a sorted array of 1000 distinct keys uses mid = ⌊(lo + hi)/2⌋ and counts one probe per element compared (the search stops when it probes the key). For how many of the 1000 keys does a successful search take exactly 10 probes?
- A. 512
- B. 489
- C. 488
- D. 500
Correct answer: B. 489
The implicit search tree is filled level by level: level k holds 2^(k−1) keys, so levels 1–9 hold 1 + 2 + … + 256 = 511 keys. The remaining 1000 − 511 = 489 keys are on level 10 (maximum 10 probes). 512 is the capacity of level 10, not its occupancy.
More Algorithms questions
- A binary min-heap holds 100 distinct keys in A[1..100]. At how many different positions can the SECOND largest key possibly be?
- Two sorted lists of 8 keys each are merged by the standard merge, which stops comparing when one list runs out. All C(16, 8) = 12870…
- What is the length of the longest common subsequence of the three strings X = BDCABACDB, Y = ABCBDABDC and Z = BCADBDACB?
- The longest repeating subsequence of a string is the longest subsequence that occurs twice, where the two copies may overlap in positions…
- Characters may be added ONLY at the front of the string abacdcabxab. What is the minimum number of characters that must be added to make…
- A digit string is decoded using A = 1, B = 2, …, Z = 26, and each code must be a valid letter number (so 0 is allowed only as part of 10…