Data Structures & AlgorithmsVery hardICPC regional · algorithm theory
Problem: What is the minimum number of comparisons in the worst case to find both the maximum and the minimum of n = 10 distinct elements using pairwise comparisons?
- A. 15
- B. 18
- C. 13
- D. 10
Correct answer: C. 13
Pairing elements costs 3n/2 - 2 = 13 comparisons for even n, which is better than 2n - 2 = 18 from scanning twice.
More Coding Interview Problems questions
- Problem: What is the information-theoretic lower bound on comparisons (in the worst case) for sorting 5 distinct elements?
- Problem: Which of the following decision problems is NP-complete?
- Problem: Which statement about the subset-sum problem with target S and n items is correct in the standard sense?
- Problem: Binary lifting on a rooted tree with n nodes uses O(n log n) preprocessing. What is the time for one LCA query?
- Problem: Which statement about building a binary heap from n given elements is correct?
- Problem: Which requirement must be met before the convex hull trick can answer queries in O(1) amortised time per query with a deque?