Data Structures & AlgorithmsVery hardICPC regional · tree queries
Problem: What is the complexity of answering distance queries on a tree after O(n log n) preprocessing with the sparse-table LCA?
- A. O(1) per query
- B. O(log n) per query
- C. O(n) per query
- D. O(sqrt n) per query
Correct answer: A. O(1) per query
The Euler-tour sparse table answers LCA queries as a range minimum in O(1).
More Coding Interview Problems questions
- Problem: In a Fenwick tree over n positions, what is the cost of a range-sum query combined with point updates?
- Problem: Which property must a function have for ternary search to find its maximum correctly?
- Problem: Dijkstra with a binary heap on a graph with E = 10^6 edges and V = 10^5 vertices runs in roughly how many elementary operations?
- Problem: Which statement about Hopcroft-Karp is correct?
- Problem: What does the Gale-Shapley algorithm guarantee for stable matching with n men and n women?
- Problem: How many states does a bitmask DP over subsets of n = 15 items have?