# 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.

- The depth of the orange node is two.
- The depth of the yellow node is two.
- The depth of the purple node is one.
- The depth of the green node is one.
- The depth of the red node is zero.

## 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*.

- The height of the red node is 2.
- The height of the green node is 0.
- The height of the purple node is 1.
- The height of the orange node is 0.
- The height of the yellow node is 0.