Chapter 16 - Python Quest
Binary Trees
Measure branches, traverse by depth and level, then search and grow binary search trees.
Treehouse Canopy Height
A treehouse architect counts how many node platforms appear on the longest path from the root platform down to a leaf.
Write tree_height(root) so it returns the number of nodes on the longest root-to-leaf path. An empty tree has height 0. The judge gives root as a TreeNode with value, left, and right attributes.
Sample checks
tree_height(root)returns3Explanation: the longest paths are 8 to 4 to either 2 or 6 and 8 to 12 to either 10 or 14, each containing three node platforms
tree_height(root)returns0Explanation: the level-order drawing is empty, so root is None and there is no node platform on any path
Hint
Hints are ready when you want one.
Lesson reference
Review: Ask the same question of both branches
Your Python
tree_height
Judge
Ready
Run your code when it feels ready.
