Knowing a bit of a tree data structure

Michael Kasingye
3 min readSep 5, 2023
erPhoto by Wolfgang Hasselmann on Unsplash

“ Let’s embark on a journey to explore what a tree data structure is and how it is used in various applications.

At its core, a tree is a hierarchical data structure that resembles a real-life tree with branches and leaves. It consists of nodes connected by edges, forming a connected and directed graph.

Here is what to note about it.

  • Root: There is a single special node at the top called the “root.” It serves as the starting point for traversing or accessing the tree. Every node in the tree is either the root itself or a descendant of the root.
  • Nodes: Each element or entity in the tree is called a “node.” Nodes contain data or information and may have zero or more child nodes. A node in a tree can be thought of as a container that holds data and pointers to its child nodes.
  • Edges: The connections between nodes are called “edges” or “branches.” Edges represent relationships between nodes and define the structure of the tree.
  • Parent and Child Nodes: In a tree, a node can have zero or more child nodes. A node with child nodes is called a “parent” node, and its children are called “child” nodes. Each child node has one parent.
  • Leaves: Nodes with no children are referred to as “leaf” nodes or “terminal” nodes. They are the nodes at the bottom of the hierarchy.
  • Subtree: A subtree is a portion of the tree that consists of a node and all its descendants, including that node. Subtrees in a tree data structure can be treated as independent trees themselves.

To understand what a tree is, let us look at a binary tree as an example.

A binary tree consists of nodes connected in a hierarchical structure where each node has at most two children, referred to as the left child and the right child. The topmost node in a binary tree is called the root node, and it serves as the starting point for traversing the tree.

Binary trees are not just abstract data structures; they have practical applications across a range of computer science domains. Here are some case I can mention:

  • File System: Your computer’s file system is likely organized using a tree structure. Directories are nodes, and files are leaves, making it easy to navigate and retrieve data.
  • Database Indexing: In databases, B-trees (a type of self-balancing binary tree) are used to index and search data efficiently. They are crucial for quick retrieval of records from large datasets.
  • Network Routing: Routing Tables implemented using binary trees can be used to represent routing tables in computer networks, helping routers efficiently route data packets to their destinations.

So, the next time you encounter a hierarchical problem or need to efficiently organize data, remember the tree data structure — an elegant and powerful tool in your computational toolkit.

RESOURCES

--

--

Michael Kasingye

I am a software developer. I love to build and work with teams to establish virtual platforms and systems that meet user satisfaction.