GATE Computer ScienceHardGATE CS (PYQ pattern)
An adversarial quicksort always splits an input of size n into parts of sizes n/10 and 9n/10, so T(n) = T(n/10) + T(9n/10) + n. For large n, the ratio (depth of the deepest leaf)/(depth of the shallowest leaf) of the recursion tree is approximately:
- A. 9
- B. 10
- C. 21.9
- D. 2.3
Correct answer: C. 21.9
Shallowest leaf: log₁₀ n. Deepest leaf: log_{10/9} n. Their ratio is ln 10 / ln(10/9) = 2.3026/0.10536 ≈ 21.9. The naive 9 or 10 comes from comparing the split ratios instead of the logarithm bases.
More Algorithms questions
- What is the minimum number of comparisons that guarantees finding the second largest of 1025 distinct numbers in the worst case?
- 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…