Tree Terminology: Path

  • Define tree-related terminologies.

Suppose $n_1, n_2, \dots, n_k$ is a sequence of nodes in a tree such that $n_1$ is the parent of $n_2$, which is the parent of $n_3$, and so on, down to $n_{k−1}$, which is the parent of $n_k$. Then $n_1, n_2, \dots, n_k$ is called a path from $n_1$ to $n_k$.

For example, the sequence $9, 17, 21, 20$ is a path from root, $9$, to leaf, $20$.

The length of a path is $k − 1$, where $k$ is the number of nodes on it.

A path may consist of a single node ($k = 1$), in which case the length of the path is $0$.