Data Structures & AlgorithmsVery hardICPC regional · tree data structures
Problem: Which statement about heavy-light decomposition for path queries on a tree is correct?
- A. Any root-to-node path crosses O(log n) light edges, so a path query costs O(log^2 n) with a segment tree per chain
- B. Every path query costs O(1) after the decomposition
- C. Path queries need O(n) time because light edges must be scanned one by one
- D. It works only for paths of length at most 2
Correct answer: A. Any root-to-node path crosses O(log n) light edges, so a path query costs O(log^2 n) with a segment tree per chain
Each light edge at least halves subtree size, so a path crosses O(log n) chains, and each chain query costs O(log n) in the segment tree.
More Coding Interview Problems questions
- Problem: Which statement about Fermat's little theorem is correct?
- Problem: What is the time for one point update and one rectangle-sum query in a 2D Fenwick tree on an n x n grid?
- Problem: Why can subtree queries on a rooted tree be answered with a range query on an array?
- Problem: An undirected graph has 10 vertices (0–9) and 6 edges: 0-1, 1-2, 3-4, 5-6, 6-7, 7-5. What is the minimum number of new edges that…
- Problem: In a graph with vertices 0–7 and edges 0-1, 1-2, 2-3, 3-0, 3-4, 4-5, 5-6, 6-4, 6-7, which edges lie on at least one cycle? How…
- Problem: In the undirected graph with edges 0-1, 0-2, 1-3, 2-3, 3-4, 4-5, what is the length of the shortest walk from 0 to 5 that uses an…