Data Structures & AlgorithmsModerateTCS NQT · comparisons
Problem: Which concept describes the minimum number of comparisons to find the maximum of n numbers?
- A. n log n comparisons
- B. n^2 comparisons
- C. n - 1 comparisons, which is optimal
- D. log n comparisons
Correct answer: C. n - 1 comparisons, which is optimal
Each comparison eliminates at most one candidate, so n - 1 comparisons are necessary and sufficient.
More Coding Interview Problems questions
- Problem: What is the Ackermann-related complexity that appears in union-find analysis?
- Problem: What is the expected number of steps for a random walk on a path of length n starting at one end to reach the other end?
- Problem: Which algorithm computes a minimum-weight perfect matching in general (non-bipartite) graphs?
- Problem: Which property must a function satisfy for the Knuth optimisation of DP to apply?
- Problem: What is the maximum number of edges in a simple planar bipartite graph with V >= 3 vertices?
- Problem: An undirected graph has vertices 0–5 and edges 0-1, 1-2, 2-0, 2-3, 3-4, 4-5, 5-3. How many edges are bridges (removal increases…