What Is a Tree and Why Study It?
Like any data structure, a tree is a collection of data that are related to one another. What makes a tree special is that it organizes information in a hierarchical way, meaning that some elements are positioned above or below others.
This is what differentiates it from a linear structure, such as a list or an array, where all elements exist at the same level.
This hierarchical organization of data is what makes the tree such a powerful structure. Let’s look at a simple example.
Imagine you have a list of 9 movies and, as a user, you want to access movie number 9. In a linear structure, you would need to go through each movie one by one until you reach it. In a tree structure, however, you can organize those movies to get there much faster. For example, your tree could start with a node called Movies. From Movies, three categories branch out: Action, Comedy, and Fantasy. From each of these categories, three movies branch out.
If the movie you’re looking for belongs to Fantasy, you only need to follow the path Movies → Fantasy → find the movie. Instead of traversing 9 elements, you would only traverse 2.

Although trees are used for much more than just making searches easier, this example helps illustrate their power. For instance, the files on your computer are organized in the form of a tree: a directory (folder) acts as a parent node, and the files or subfolders inside it are its child nodes.
If you have programming experience, you may have noticed that the DOM (Document Object Model) is also represented as a tree of elements. In addition, many algorithms used to sort data or perform arithmetic calculations rely on tree structures to achieve their goals efficiently.
However, before diving into how trees are used in programming, it is essential to clearly understand their basic components.
Components of a Tree
A tree is made up of nodes. Each node is a piece of data that connects to other nodes.
The first node in a tree is called the Root Node.
From the root node, all other nodes in the tree are derived.
There are different types of nodes based on their relationship to others:
- Parent node: a node from which at least one child node is derived.
- Child node: a node that has at least one parent.
- Sibling node: a node that shares the same parent as another node.
- Leaf node: a child node that does not have any children. These are the final elements of the tree.

Path in a Tree
A key concept for understanding how a tree works is the path.
A path is the sequence of nodes that are traversed from one node to another.
To understand this, we first need to introduce the concept of an edge. An edge is the connection between two nodes. Every time a parent node connects to a child node, there is an edge between them.
Returning to the movie example, the path to movie 1 would be:
Movies → Fantasy → 1
In this traversal:
- Each arrow represents an edge.
- Each move from one node to another is a jump.
The path length is defined as the number of edges between the starting node and the destination node. In this case, the path length is 2, since two edges are traversed.
Another simple way to think about it is to ask:
How many jumps do I need to reach the node I’m looking for?

Path Restrictions in a Tree
An important characteristic of a standard data tree is that nodes are only connected through parent–child relationships. This leads to two fundamental rules:
- You cannot move directly from one node to its sibling.
- There is only one unique path between any two nodes.
Continuing with the movie tree example: if my program is currently positioned at the Action node, I cannot go directly to Fantasy, since they are sibling nodes. I must first go up to the parent node Movies, then down to Fantasy, and finally reach movie 1.
The path would be:
Action → Movies → Fantasy → 1
In this case, the path length is 3, because three jumps are required to reach the destination.

Other Important Characteristics
- Level: the level of a node indicates its position relative to the root. In some cases, the root is considered level 0, and in others level 1. What matters is that each new generation of child nodes represents a new level.
- Height: the total number of levels in a tree. In some cases, a maximum height is defined before the tree is created.
- Weight: the total number of nodes contained in the tree.
- Order: a predefined value that indicates the maximum number of child nodes a parent node can have. For example, a binary tree has an order of 2, meaning each node can have at most two children.
- Degree: the number of child nodes a parent node has. A node with three children has a degree of 3. The degree may be limited by the order, but not necessarily.
- Degree of the tree: the maximum degree among all nodes in the tree.
Final Notes
Now that you have a clearer understanding of what a tree structure is, we can focus on how to use it in programming. Below, you’ll find related posts with tutorials and practical examples that will help you dive deeper into trees and see them in action.