Tree ADT: Path 7
A
F
K L M
E
Q
J
P
I
D
H
C
Path from A to Q is A-E-J-Q
• A path from node n1
to nk
is defined as a sequence of nodes n1
, n2
, . . . , nk
such that ni
is the
parent of ni+1 for 1 to i < k.
• The length of this path is the number of edges on the path, namely k-1. There is a path of length
zero from every node to itself.
• Notice that in a tree there is exactly one path from the root to each node
• No circle in tree
• For any node ni
, the depth of ni
is the
length of the unique path from the root
to ni
. Thus, the root is at depth 0.
• The height of ni
is the longest path from ni
to a leaf. Thus all leaves are at height 0.
• The height of a tree is equal to the
height of the root.