Depth and Height of a Tree

19/October/2014 by Valkryst, Updated 29/June/2017

The following post is derived from notes taken while reading through this textbook.

For the purpose of this post, we will be using this tree.

Some of the terms used in this post have been defined here.


The depth of a node is the number of ancestors (parents of parents) of the node, excluding the node itself.


The height of a node is the height of it's highest child node plus one.

Because the height of the purple node is 1 and the height of the green node is 0, the red node uses the height of the purple node and adds one. Therefore the height of the red node is heightOfPurpleNode + 1 = heightOfRedNode which translates into 1 + 1 = 2.

Additional Information: