Graph Theory37 sections · 1633 units
Open in CourseQuiz: Tree Diameter
Knowledge check
Check Your Understanding
The diameter of a tree is the longest path between any nodes. In a DFS-based solution, you track the deepest subtrees at each node. Why do you need the deepest and not just the deepest?
- A.The second deepest subtree is needed for space complexity reasons
- B.You need subtrees to handle the case where the tree is unbalanced
- C.The deepest subtree alone gives the tree height, not the diameter
- D.The longest path through a node goes down into different children, so you combine both depths