Data Structures & AlgorithmsModerateICPC regional · algorithm theory
Problem: What is the worst-case number of comparisons to merge two sorted lists of lengths m and n?
- A. m + n - 1
- B. max(m, n)
- C. m * n * 2
- D. m + n
Correct answer: A. m + n - 1
Each comparison outputs one element, and the last element needs no comparison, giving m + n - 1.
More Coding Interview Problems questions
- 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…
- Problem: Strings "axbycz" and "abc" are given. Count the subsequences of "axbycz" that equal "abc" (indices must be increasing, and…