Data Structures & AlgorithmsVery hardGATE CS · competitive programming
Finding the k-th smallest element with a median-of-medians pivot is used as a deterministic selection method. What is its worst-case time complexity?
- A. O(n log k)
- B. O(n log n)
- C. O(n)
- D. O(n²)
Correct answer: C. O(n)
The median-of-medians pivot guarantees a split of at least 30% on each side, so T(n) ≤ T(n/5) + T(7n/10) + O(n), which solves to O(n). A fixed-pivot quickselect can degrade to O(n²).
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Four sorted lists of sizes 7, 5, 3 and 2 are merged pairwise, always merging the two currently smallest lists first. What is the total…
- How many non-empty contiguous subarrays of [3, 5, 6, 1, 2, 3, 4] have bitwise XOR equal to 0?
- How many non-empty contiguous subarrays of [2, 2, 3, 3, 3, 2] consist of one repeated value only?
- How many non-empty contiguous subarrays of [1, 2, 4, 3, 6, 5, 7, 8] contain equally many even and odd numbers?
- What is the length of the longest contiguous subarray of [5, 3, 4, 2, 1, 9, 6] whose sum is divisible by 6?
- How many index pairs i < j satisfy a[i] - i = a[j] - j for the array [7, 3, 5, 8, 6, 9, 4, 10] (0-based indices)?