figure height-balanced binary tree of height write program that takes as input the root of binary tree and checks whether the tree is heightbalanced hintthink of classic binary tree algorithm solutionhere is brute-force algorithm compute the height for the tree rooted at each node recursively the basic computation is to compute the height for each node starting from the leavesand proceeding upwards for each nodewe check if the difference in heights of the left and right children is greater than one we can store the heights in hash tableor in new field in the nodes this entails (nstorage and (ntimewhere is the number of nodes of the tree we can solve this problem using less storage by observing that we do not need to store the heights of all nodes at the same time once we are done with subtreeall we need is whether it is height-balancedand if sowhat its height is--we do not need any information about descendants of the subtree' root def is_balanced_binary_tree (tree)balancedstatuswithheight collections namedtuple 'balancedstatuswithheight '('balanced ''height ')first value of the return value indicates if tree is balanced and if balanced the second value of the return value is the height of tree def check_balanced (tree)if not treereturn balancedstatuswithheight (true - base case left_result check_balanced (tree leftif not left_result balanced left subtree is not balanced return balancedstatuswithheight (false right_result check_balanced (tree right if not right_result balanced right subtree is not balanced return balancedstatuswithheight (false is_balanced absleft_result height right_result height < height maxleft_result height right_result height return balancedstatuswithheight is_balanced height