Search⌘ K

Calculating the Height of a Binary Tree

Explore how to calculate the height of a binary tree by understanding node heights and applying recursion. This lesson teaches you to traverse left and right subtrees and combine their heights for the overall tree height using Python code.

Height of Tree

Let’s start by defining the height of a tree. The height of a tree is the height of its root node. Now let’s see what we mean by the height of a node:

Height of Node

The height of a node is the number of edges on the longest path between that node and a leaf. The height of a leaf node is 0.

Recursively defined, the height of a node is one greater than the max of its right and left ...