Question: Write a method int height(Node root) that takes the root of a binary search tree as a parameter and returns the height of the tree.

Write a method int height(Node root) that takes the root of a binary search tree as a parameter and returns the height of the tree. The height is the number of edges in the longest path from root to leaf (a tree with only 1 node should have a height of 0, and an empty tree should have a height of -1). First handle the base case, then calculate the height recursively: 1 + (the larger height of the two subtrees)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!