A rooted tree is a tree with one distinguished vertex called the root.
The root gives direction to an otherwise undirected structure. In an unrooted tree, no vertex has a privileged role. In a rooted tree, every vertex is understood by its position relative to the root. This turns a tree into a hierarchy.
Rooted trees are used to model ancestry, containment, dependency, syntax, search, decisions, and recursive computation.
28.1 Definition
Let
be a tree.
A rooted tree is a pair
where is a distinguished vertex called the root.
The underlying graph remains an ordinary tree. The choice of root adds extra structure.
If is any vertex of , then there is a unique simple path from to . This path determines the position of in the rooted tree.
28.2 Parent and Child
Let be a vertex different from the root.
Since there is a unique path from the root to , there is a unique vertex immediately before on that path. This vertex is called the parent of .
If is the parent of , then is called a child of .
The root has no parent.
A vertex may have zero, one, or many children. A vertex with no children is called a leaf. A vertex with at least one child is called an internal vertex.
28.3 Ancestors and Descendants
Let and be vertices in a rooted tree.
The vertex is an ancestor of if lies on the unique path from the root to .
The vertex is then called a descendant of .
Every vertex is often counted as both an ancestor and a descendant of itself. When this convention is inconvenient, one uses the terms proper ancestor and proper descendant.
The root is an ancestor of every vertex. Every vertex is a descendant of the root.
28.4 Depth and Height
The depth of a vertex is the length of the unique path from the root to .
Thus the root has depth
If has parent , then
The height of a rooted tree is the maximum depth of any vertex:
A tree with one vertex has height .
The height measures how far the tree extends from its root.
28.5 Levels
The vertices at the same depth form a level.
The level of a rooted tree is the set
The root is the only vertex at level :
Levels provide a natural horizontal decomposition of the tree. They are especially useful in breadth-first search, shortest-path trees, and hierarchical data structures.
28.6 Subtrees
Let be a vertex in a rooted tree.
The subtree rooted at is the subgraph induced by and all descendants of .
This subtree is itself a rooted tree with root .
Subtrees are the basic units of recursive reasoning. Many proofs and algorithms on rooted trees work by applying the same argument to each subtree.
If the children of are
then the subtree rooted at consists of together with the subtrees rooted at those children.
28.7 Recursive Description
A rooted tree may be described recursively.
It consists of a root together with a finite collection of rooted subtrees attached to the root.
If the root has children
then each is the root of a smaller rooted tree.
This gives the schematic form
where is the subtree rooted at .
If , then the tree consists only of the root, or the root is a leaf.
This recursive structure explains why rooted trees are central in algorithms and formal languages.
28.8 Ordered and Unordered Rooted Trees
A rooted tree may be ordered or unordered.
In an unordered rooted tree, the children of a vertex form a set. Their order has no meaning.
In an ordered rooted tree, the children of each vertex are arranged in a specified order, usually from left to right.
For example, if a vertex has children , , and , then the ordered list
differs from
Ordered rooted trees appear in syntax trees, expression trees, XML documents, JSON structures, and many parsing systems.
Unordered rooted trees appear in abstract hierarchy, taxonomy, and many mathematical counting problems.
28.9 Rooted Trees as Directed Graphs
A rooted tree can be converted into a directed graph by orienting every edge away from the root.
If is the parent of , then the undirected edge
becomes the directed edge
The resulting directed graph has these properties:
| Property | Meaning |
|---|---|
| Root in-degree | The root has in-degree |
| Non-root in-degree | Every other vertex has in-degree |
| Acyclicity | There are no directed cycles |
| Reachability | Every vertex is reachable from the root |
Such a directed rooted tree is often called an arborescence.
One may also orient every edge toward the root. In that convention, every non-root vertex points to its parent.
28.10 Lowest Common Ancestor
Let and be two vertices in a rooted tree.
A common ancestor of and is a vertex that is an ancestor of both.
The lowest common ancestor, often written
is the common ancestor of and with greatest depth.
The lowest common ancestor is unique.
Example
If two files lie in different subdirectories, their lowest common ancestor is the deepest directory containing both files.
The lowest common ancestor is important in algorithms, tree queries, phylogenetics, compilers, and network routing.
28.11 Paths in Rooted Trees
In an unrooted tree, every two vertices are joined by a unique simple path.
In a rooted tree, this path can be described using ancestors.
Let and be vertices, and let
Then the path from to goes upward from to , then downward from to .
Thus
This formula is widely used in tree algorithms.
28.12 Rooted Tree Traversals
A traversal is a systematic procedure for visiting the vertices of a tree.
For rooted trees, common traversals include:
| Traversal | Rule |
|---|---|
| Preorder | Visit root, then subtrees |
| Postorder | Visit subtrees, then root |
| Level order | Visit vertices by increasing depth |
If the tree is ordered, the subtrees are visited according to the specified child order.
Preorder traversal is natural when a parent must be processed before its children.
Postorder traversal is natural when a parent depends on information computed from its children.
Level-order traversal is the same structure used by breadth-first search.
28.13 Size of a Rooted Tree
The size of a rooted tree is the number of vertices it contains.
The recursive formula for size is
where are the subtrees rooted at the children of the root.
The term counts the root.
This formula reflects the decomposition of the tree into root plus child subtrees.
28.14 Height Recursion
The height of a rooted tree can also be computed recursively.
If the root has no children, then
If the root has child subtrees
then
Thus a tree is tall when at least one of its subtrees is tall.
This recursion is used in the analysis of search trees, decision trees, and divide-and-conquer algorithms.
28.15 Branching Factor
The number of children of a vertex is its branching factor.
A rooted tree has maximum branching factor if every vertex has at most children.
If every internal vertex has exactly children, the tree is called a full -ary tree.
For example:
| Branching factor | Name |
|---|---|
| Path-like rooted tree | |
| Binary tree | |
| Ternary tree | |
| -ary tree |
Branching factor controls the growth of levels.
If a rooted tree has branching factor at most , then level contains at most
vertices.
28.16 Counting Vertices by Height
Suppose a rooted tree has maximum branching factor and height .
Then the number of vertices is at most
If , this sum is
If , the tree is a path and has at most
vertices.
These formulas are common in the analysis of search algorithms.
28.17 Applications
Rooted trees appear whenever structure has a distinguished origin or hierarchy.
| Application | Rooted tree interpretation |
|---|---|
| File system | Root directory and nested folders |
| Syntax tree | Grammar production hierarchy |
| Decision tree | Root question and branch outcomes |
| Search tree | Initial state and generated states |
| Organization chart | Top-level unit and subordinate units |
| Phylogenetic tree | Common ancestor and descendants |
| Web crawling | Seed page and discovered links |
The same mathematical structure supports many different interpretations.
28.18 Summary
A rooted tree is a tree with a distinguished vertex called the root.
The root induces parent-child relations, ancestors, descendants, depths, levels, and subtrees. These notions turn a tree into a hierarchical structure.
Rooted trees are naturally recursive. A rooted tree consists of a root and the rooted subtrees attached to its children.
This recursive and hierarchical structure makes rooted trees fundamental in algorithms, data structures, parsing, search, and dependency modeling.