GATE Computer ScienceModerateGATE CS (PYQ pattern)
A binary min-heap holds 100 distinct keys in A[1..100]. At how many different positions can the SECOND largest key possibly be?
- A. 50
- B. 52
- C. 51
- D. 49
Correct answer: C. 51
Every descendant of the second largest key must be larger than it, so its subtree can contain at most one other node (the largest key). That allows the 50 leaves (positions 51–100) and the internal node 50, whose only child is position 100: 51 positions. Brute force on small heaps confirms the subtree-size ≤ 2 rule.
More Algorithms questions
- 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…
- What is the maximum product of a non-empty contiguous subarray of [−2, 3, −4, 0, 5, −1, 2, −3, −1, 4]?