Question: PYTHON : Figuring whether height balance property satisfied of Binary Tree(Method in LINEAR Time) Question 3: Although we originally defined the height ofa subtree rooted
PYTHON : Figuring whether height balance property satisfied of Binary Tree(Method in LINEAR Time)


Question 3: Although we originally defined the height ofa subtree rooted at r to be the number of edges on the longest path from r to a leaf, for the simplicity of the definitions in this question, we will modify this definition so the height of a subtree rooted at r will be the number of nodes on such a longest path. By this definition, a leaf node has height 1, while we trivially define the height of a "None" child to be 0. We give the following definition, for what is considered to be a balanced tree: We say that a binary treeT satisfies the Height-Balance Property if for every node p of the heights of the children of p differ by atmost 1. For example, consider the following two trees. Note that in these figures we showed the height of each subtree to the right of each such root, in a (small) red font: The tree on the left satisfies the height-balance property, while the tree on the right does not (since the subtree rooted by the node containing 2 has one child with height 2 and the second child with height 0)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
