9.7 Trees 303 containing 2. The descendants of the node containing 3 are the nodes with the values 5, 6, 8, 9, and 10. A node is the ancestor of another node if it is the parent of the node or the parent of some other ancestor of that node. (Yes, this is a recursive definition.) The ancestors of the node with the value 9 are the nodes containing 5, 3, and 1. Obviously, the root of the tree is the ancestor of every other node in the tree. The level of a node refers to its distance from the root. If we designate the level of the root as 0 (zero), the nodes containing 2 and 3 are Level 1 nodes, the nodes containing 4, 5, and 6 are Level 2 nodes, and the nodes containing 7, 8, 9, and 10 are Level 3 nodes. The maximum level in a tree determines its height . Because we are refer-ring to a binary tree, the maximum number of nodes at any level N is 2 N . Often, however, levels do not contain the maximum number of nodes. For instance, in Figure 9.16, Level 2 could contain four nodes, but because the
This is the end of the preview.
access the rest of the document.