GATE Computer ScienceModerateGATE CS (PYQ pattern)
What is the minimum number of comparisons that guarantees finding the second largest of 1025 distinct numbers in the worst case?
- A. 1033
- B. 1034
- C. 1035
- D. 2047
Correct answer: B. 1034
The optimal bound is n + ⌈log₂ n⌉ − 2. Since 1024 < 1025, ⌈log₂ 1025⌉ = 11, giving 1025 + 11 − 2 = 1034: a knockout tournament (1024 comparisons) whose winner played up to 11 matches, then 10 comparisons among those 11 losers. Using log₂ ≈ 10 gives the trap 1033.
More Algorithms questions
- Top-down merge sort splits n elements into a left part of ⌈n/2⌉ and a right part of ⌊n/2⌋, and its merge stops comparing as soon as one…
- The keys 3, 9, 2, 1, 4, 5, 7, 8, 6, 10, 11, 12 are inserted, in this order, one at a time into an initially empty binary max-heap, each…
- The array [5, 3, 17, 10, 84, 19, 6, 22, 9, 15, 2] is turned into a max-heap by Floyd's linear-time Build-Max-Heap. Which array results?…
- Insertion sort on [7, 3, 9, 1, 8, 2, 6, 5, 4] scans left-to-right from position j = i − 1, comparing a[j] with the key until a[j] ≤ key or…
- Lomuto partition (pivot = last element, loop j from lo to hi−1 comparing a[j] ≤ pivot) is used in quicksort on [5, 2, 8, 1, 9, 3, 7, 4…
- A randomised quicksort on a random permutation of n distinct keys picks a pivot uniformly and every partition of m elements costs exactly…