Data Structures

Rooted Trees in Graph Theory

From the files on your computer to the HTML on this very page, rooted trees quietly organize the digital world. Here is how they work.

10 Min Read Updated: June 2026 Intermediate Level
LGT
Learn Graph Theory Team
Expert Operations Research Engineers

1. What Is a Rooted Tree?

In graph theory, a tree is a connected graph with no cycles. A rooted tree is simply a tree in which one special vertex has been chosen as the root. That single choice gives every other node a clear sense of "up" (toward the root) and "down" (away from it), turning a plain tree into a hierarchy.

A useful fact: a tree with n nodes always has exactly n - 1 edges, and there is precisely one path between any two nodes — no more, no less.

2. Key Terminology

3. Rooted vs Unrooted Trees

An unrooted tree only describes which nodes are connected — there is no top or bottom. The moment you pick a root, the same set of edges gains direction: edges are now understood as pointing away from the root, so a rooted tree behaves like a special kind of directed graph. Choosing a different root produces a different hierarchy from the very same underlying tree.

See Trees in Motion

Build a rooted tree and watch DFS and BFS traversals light up node by node. Depth, height, and parent-child links suddenly make sense.

Launch the Visualizer

4. How Rooted Trees Are Represented

There are three common ways to store a rooted tree in code:

5. Types of Rooted Trees

6. Traversing a Rooted Tree

Visiting every node is called traversal, and there are two broad families:

If these sound familiar, that is because they are the same strategies used on general graphs. See our deep dive on BFS vs DFS.

7. Real-World Applications

Frequently Asked Questions

What is the difference between a rooted and an unrooted tree?

An unrooted tree only specifies which nodes are connected. A rooted tree designates one node as the root, giving the tree a hierarchy with parent-child relationships and a clear top.

What is the difference between the depth and height of a tree?

Depth is the distance from the root down to a particular node (the root has depth 0). Height is the distance from a node down to its deepest leaf; the tree's height is the height of the root.

Is a rooted tree a directed graph?

It can be viewed as one. Once a root is chosen, every edge is implicitly oriented away from the root, giving each non-root node exactly one parent.

How many edges does a tree with n nodes have?

Exactly n - 1. Adding any further edge would create a cycle, and a tree by definition has none.

Further Exploration

Grow Your Own Tree

The fastest way to understand rooted trees is to build one and traverse it. Create nodes, set a root, and watch the structure come alive.

Open the Visualizer