# What Is Tree in Data Structure With Real Life Example?

//

Angela Bailey

A tree is a fundamental data structure in computer science that represents a hierarchical structure. It consists of nodes connected by edges, where each node can have zero or more child nodes. The topmost node in a tree is called the root, and every other node is either an internal node or a leaf node.

## Real-Life Example of a Tree

To understand trees better, let’s consider a real-life example – the family tree. A family tree represents the relationships and connections between family members across different generations. In this context, each person can be considered as a node, and the relationships between them form the edges.

For instance, let’s take the example of the Smith family:

• John Smith is the root of the tree, representing the oldest generation.
• Mary Smith, Emily Smith, and Michael Smith are John’s children and form the first level of nodes from the root.
• Sarah Johnson, who married Michael Smith, becomes part of the family tree as an external member.
• Liam Smith, Ethan Smith, and Hannah Johnson are Sarah and Michael’s children.
• Kate Thompson, who married Liam Smith, becomes part of the family tree as an external member.
• Jacob Thompson is Kate and Liam’s child.

This hierarchical representation allows us to visualize how different individuals are related to one another within a family context. Similarly, trees can be used to represent various other hierarchical structures in computer science such as organization charts or file systems.

## Key Concepts of Trees

Now that we have a real-life example of a tree, let’s explore some key concepts related to trees:

### Root

The root is the topmost node in a tree, representing the starting point or the overall parent of all other nodes in the tree. In the family tree example, John Smith is the root.

### Node

A node represents an individual element within a tree. Each node may contain data and may also have references or links to its child nodes. In our family tree example, each person’s name represents a node.

### Edge

An edge represents a connection or link between two nodes in a tree. It defines the relationship between parent and child nodes. For instance, in our family tree example, the edges connect John Smith to his children (Mary Smith, Emily Smith, and Michael Smith).

### Child Node

A child node is a node that has an edge originating from another node called its parent. In our family tree example, Mary Smith, Emily Smith, and Michael Smith are John Smith’s children.

### Parent Node

A parent node is a node from which an edge originates towards its child nodes. In our family tree example, John Smith is the parent of Mary Smith, Emily Smith, and Michael Smith.

### Leaf Node

A leaf node is a node that does not have any child nodes in a tree. It represents the end of a branch or path within the hierarchy. For instance, Hannah Johnson and Jacob Thompson are leaf nodes in our family tree.

Trees provide an efficient way to store and organize data with hierarchical relationships. They offer quick access and manipulation of data, making them crucial in various computer science applications.

So, the next time you encounter a hierarchical structure or need to organize data in a tree-like manner, remember to consider using a tree data structure.