Skip to main content

Practice · 3 of 3

Same Tree, Different Words

CHALLENGE
Difficulty: advanced+25 XP

**Scenario.** A tree with n ≤ 100000 nodes; count paths of exactly k edges. k can be up to n. Which decomposition is the intended one? **Which approach is the best fit? The program only needs to print the letter.** **A)** DFS from every node, walking k steps — O(n·k) worst case **B)** Count paths by their highest node (centroid): combine partial depths from different child branches with a convolution-like merge **C)** Floyd–Warshall over the tree and count distances equal to k **D)** Binary search on k since more edges means fewer paths

Back to lesson: Practice: Decomposition Drills