GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A randomised quicksort on a random permutation of n distinct keys picks a pivot uniformly and every partition of m elements costs exactly m − 1 comparisons. What is the exact expected number of comparisons for n = 6?
- A. 9.1
- B. 11.7
- C. 10.3
- D. 12.5
Correct answer: C. 10.3
C(n) = (n − 1) + (2/n)ΣC(i) gives C(1..6) = 0, 1, 8/3, 29/6, 37/5, 103/10, so C(6) = 10.3. This also equals 2(n+1)H_n − 4n = 14·2.45 − 24 = 10.3.
More Algorithms questions
- Binary search on a sorted array of 20 distinct keys uses mid = ⌊(lo + hi)/2⌋ and one three-way comparison per probe, stopping when lo >…
- A base-3 (ternary) counter starts at 0 and is incremented 1000 times. The cost of an increment is the number of digits that change…
- A dynamic array starts with capacity 2. When it is full and an element is appended, the capacity becomes ⌈1.5 × capacity⌉ and all current…
- Consider t(n): if n ≤ 2 return 1; else return t(n−1) + t(n−2) + t(n−3). How many calls to t (including the initial call) are made when…
- How many times is x++ executed? for (i = 2; i <= 100; i++) for (j = ii; j <= 100; j += i) x++;
- How many times is x++ executed? for (i = 1; i <= 1000; i = 2) for (j = i; j >= 1; j /= 3) x++; (integer division)