Two K Minus One
A virtual tree built from k key nodes of an n-node tree. How big is it, and why?
At most 2k−1 nodes: sort the key nodes by DFS order and add the LCA of each adjacent pair. Every added node is a branching point of the key set, and a tree with k leaves has fewer than k internal branchings. Construction is Θ(n) per query, rerunning the DFS.
At most 2k−1 nodes: sort the key nodes by DFS order and add the LCA of each adjacent pair. Every added node is a branching point of the key set, and a tree with k leaves has fewer than k internal branchings. Construction is O(klogn).
Θ(klogn) nodes: sort the key nodes by DFS order and add the LCA of each adjacent pair. Every added node is an ancestor of some key node, and a tree of depth logn contributes one chain per key node. Construction is O(klogn).
At most 2k−1 nodes: sort the key nodes by DFS order and add the LCA of every pair. Every added node is a branching point of the key set, and a tree with k leaves has fewer than k internal branchings. Construction is O(k2logn).
Sign in to answer questions and track your progress
Sign In