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

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

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

## Additional Information:

- Notable pages from the textbook:
- Page 287 - Pseudocode algorithm for finding the depth of a node.
- Page 289 - Pseudocode algorithm for finding the height of a node.