GATE Computer ScienceHardGATE CS (PYQ pattern)
Let T(n) = 2T(n/2) + n·log₂ n for n ≥ 2, T(1) = 1, with n = 2^k. Which is the exact closed form of T(n)?
- A. n·(1 + k(k−1)/2)
- B. n·k(k+1)/2
- C. n·(1 + k²/2)
- D. n·(1 + k(k+1)/2)
Correct answer: D. n·(1 + k(k+1)/2)
Divide by n: U(k) = T(2^k)/2^k satisfies U(k) = U(k−1) + k, U(0) = 1, so U(k) = 1 + (1 + 2 + … + k) = 1 + k(k+1)/2. Check k = 1: T(2) = 2·1 + 2·1 = 4 = 2·(1 + 1). The k(k−1)/2 form sums one level too few; dropping the 1 forgets the n leaves.
More Algorithms questions
- 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…
- 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…