Data Structures & AlgorithmsVery hardICPC regional · selection
Problem: Which is the worst-case time complexity of the median-of-medians selection algorithm for finding the k-th smallest element of n numbers?
- A. O(n log n) on average only
- B. O(n^2) worst case
- C. O(n log k) worst case
- D. O(n) worst case
Correct answer: D. O(n) worst case
Choosing the pivot as the median of groups of five guarantees a constant fraction is discarded, giving a linear recurrence T(n) = T(n/5) + T(7n/10) + O(n).
More Coding Interview Problems questions
- Problem: What is the worst-case number of comparisons to merge two sorted lists of lengths m and n?
- Problem: For coprime m and n, which identity for Euler's totient function is correct?
- Problem: An undirected graph has vertices 0–7 and edges 0-1, 0-2, 1-2, 2-3, 4-5, 5-6, 6-4, 6-7. How many connected components contain at…
- Problem: Vertices 0–5 form a directed graph with arcs 0→1, 1→2, 2→3, 3→1, 3→4, 4→5, 5→4. Let S be the set of vertices reachable from 0…
- Problem: Kruskal's algorithm on the edges 0-1 (3), 1-2 (1), 0-2 (2), 2-3 (5), 1-3 (4), 3-4 (2), 2-4 (6) processes the edges in increasing…
- Problem: A tree has 7 nodes labelled 1–7 with edges 1-2, 1-3, 3-4, 3-5, 5-6, 5-7. Node 1 is the root. What is the depth of the deepest…