Data Structures & AlgorithmsHardICPC regional · algorithm theory
Problem: What is the expected time of Rabin-Karp string matching with a good polynomial hash?
- A. O(nm) always
- B. O(n + m) expected
- C. O(n log m) always
- D. O(m^2) always
Correct answer: B. O(n + m) expected
Rolling hashes give O(1) updates per shift and verify candidate matches, so the expected total is linear.
More Coding Interview Problems questions
- Problem: How many pairs (i < j) of the array 1..14 have a[i] + a[j] divisible by 7? Run the code. python a = list(range(1, 15))…
- Problem: Which is the worst-case time complexity of the median-of-medians selection algorithm for finding the k-th smallest element of n…
- 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…