Tree Definitions A graph is a set G = (V, E), where V is a (normally non-empty) set of vertices (singular vertex) and E (for edges) is a (possibly empty) set of (normally unordered) pairs of vertices. Vertices are sometimes called nodes (as in trees, which are special cases of graphs). Edges may be ordered, in which case they are often called arcs. A graph with ordered edges is said to be directed, and is called a digraph. Graphs with unordered edges are sometimes called undirected graphs, to differentiate them from digraphs. Duplicate edges/arcs usually are not allowed. An edge or arc from a vertex to itself is called a loop. A sequence of edges from a vertex through one or more other vertices, without passing through any vertex twice, and going back to the original vertex, is called a cycle, and a graph with no cycles is said to be acyclic. A tree is a graph with special properties. In trees, the vertices are normally called nodes. Trees may be either directed or undirected graphs (some texts restrict this to digraphs). Trees are always acyclic. One way to define the properties of trees is recursively: A tree is either empty; or it has a special node r, called the root, and zero or more non-empty subtrees T1, T2, ..., Tk, the roots of each being connected by an arc from r. The root of each subtree of r is said to be a child of r, and r is the parent of each subtree root. We may define grandparent and grandchild similarly, e.g., a parent's parent or a child's child. Nodes with no children are called leaves (singular leaf) or exterior, external, outer, or terminal nodes. Any node with at least one child is an interior (or internal, inner, or branch) node. Nodes with the same parent are called siblings. A path from node n1 to nk is defined as a sequence of nodes n1, n2, ..., nk such that ni is the parent of n(i+1) for 1 ≤ i < k. The length of this path is the number of arcs on the path, or k-1. There is assumed to be a path of zero length from any node in a tree to itself. There will be at most one path from any node in the tree to any other node in the tree. For any node ni, the depth of ni is defined to be the length of the unique path from the root to ni. The root is at depth zero. The height of any node ni is the length of the longest path from ni to a leaf. The height of the tree is the height of the root. All nodes at the same depth are at the same level, with the root at level zero, its children at level one, etc. If there exists a path from n1 to n2, n1 is an ancestor of n2, and n2 is a descendant of n1. If n1 ≠ n2, then n1 is a proper ancestor of n2, and n2 is a proper descendant of n1. Normally, when we talk about ancestors or descendants, we imply proper ancestors and descendants. An n-ary tree is a tree where each node has no more than n children. A binary tree in an n-ary tree with n = 2. The children of any node in a binary tree are called the left child or the right child, depending on the side they are on compared to their parent. A full binary tree is one where all levels that contain nodes have the maximum possible number of nodes. A complete binary tree is one in which all levels except the last have the maximum possible number of nodes, and the last level is full from the left. Loops are not allowed in a tree, therefore for a tree of n nodes, there will be exactly n-1 arcs.