GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Quicksort partitions m elements with exactly m − 1 comparisons and then recurses on the two sides (sizes k and m − 1 − k). Over all inputs and pivot choices, what is the minimum possible total number of comparisons for n = 20?
- A. 58
- B. 50
- C. 66
- D. 54
Correct answer: D. 54
Let B(m) = m − 1 + min_k [B(k) + B(m − 1 − k)], B(0) = B(1) = 0. Balanced splits are best: B(3) = 2, B(4) = 4, B(7) = 10, B(9) = 16, B(10) = 19, B(15) = 34, and B(20) = 19 + B(9) + B(10) = 19 + 16 + 19 = 54. 58 is B(21).
More Algorithms questions
- Keys 50, 30, 70, 20, 40, 60, 80 are inserted in this order into an empty binary search tree. How many of the 7! insertion orders of these…
- Floyd's cycle-finding is applied to the sequence x₀ = 2, x{i+1} = (xi² + 1) mod 55. How many distinct values does the sequence take?
- Bellman–Ford is run from A on the directed graph A→B 4, A→C 2, C→B 1, B→D 5, C→D 8, D→E 3, C→E 10, E→F −2, D→F 6. In each pass the edges…
- Assume P ≠ NP. Which of the following problems have a polynomial-time algorithm? I. 2-SAT. II. 3-colourability of a graph. III. Maximum…
- A polynomial-time many-one reduction from problem A to problem B is given (A ≤ₚ B). Which statements must be true? I. If B ∈ P then A ∈ P…
- Median-of-medians selection with groups of 7 satisfies T(n) ≤ T(n/7) + T(5n/7) + cn (ignore floors). Guessing T(n) ≤ an, what is the…