Depth and Height of a Tree

Published , Updated

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

Depth

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

Height

The height of a node is the height of its 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.