Calculating the Height of a Binary Tree
In this lesson, you will learn how to calculate the height of a binary tree.
We'll cover the following
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 children’s height.
Below is an example of a binary tree labeled with heights of individual nodes:
Get hands-on with 1400+ tech skills courses.