Data Structures & AlgorithmsVery hardICPC regional · tree decomposition
Problem: Which claim about the centroid decomposition of a tree is correct?
- A. Its depth is always n
- B. It works only on paths
- C. It needs O(n^2) memory always
- D. Every level has subtrees at most half the size, so the depth is O(log n)
Correct answer: D. Every level has subtrees at most half the size, so the depth is O(log n)
Removing a centroid leaves components of size at most n/2, giving logarithmic depth.
More Coding Interview Problems questions
- Problem: What is the complexity of answering distance queries on a tree after O(n log n) preprocessing with the sparse-table LCA?
- 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?