0
0
Data Structures Theoryknowledge~6 mins

Binary tree terminology in Data Structures Theory - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine organizing information in a way that each piece connects to two others at most, like a family tree. Understanding the special words used to describe parts of this structure helps us work with it clearly and easily.
Explanation
Node
A node is a single element or point in the tree that holds data. Each node can connect to other nodes, forming the structure of the tree.
A node is the basic building block of a binary tree.
Root
The root is the very first node at the top of the tree. It is the starting point from which all other nodes branch out.
The root node is the entry point to the entire binary tree.
Parent and Child
A parent node is one that has branches leading to other nodes called children. Each child node connects back to exactly one parent.
Parent nodes connect downward to child nodes, showing relationships.
Leaf
A leaf node is a node that does not have any children. It is at the end of a branch in the tree.
Leaf nodes mark the ends of branches in a binary tree.
Edge
An edge is the connection or link between two nodes, showing the relationship from parent to child.
Edges are the lines that connect nodes in the tree.
Subtree
A subtree is any node along with all its descendants, forming a smaller tree within the larger tree.
Subtrees are smaller trees inside the main binary tree.
Depth and Height
Depth is how far a node is from the root, counting steps down. Height is how far the farthest leaf is from a node, counting steps down.
Depth measures distance from root; height measures distance to farthest leaf.
Real World Analogy

Think of a family tree where the oldest ancestor is at the top. Each person (node) has parents and children, and some people have no children, ending their branch. The lines connecting family members show relationships.

Node → A person in the family tree
Root → The oldest ancestor at the top of the family tree
Parent and Child → Parents and their children in the family
Leaf → A family member with no children
Edge → The line connecting a parent to a child
Subtree → A branch of the family starting from one person
Depth and Height → Depth is how many generations from the oldest ancestor; height is how many generations down to the youngest descendant
Diagram
Diagram
        ┌─────┐
        │Root │
        └──┬──┘
       ┌────┴────┐
    ┌──┴──┐   ┌──┴──┐
    │ P1  │   │ P2  │
    └─┬───┘   └─┬───┘
   ┌──┴──┐    ┌─┴─┐
   │L1   │    │L2 │
   └─────┘    └───┘
This diagram shows a binary tree with a root node, parent nodes (P1, P2), and leaf nodes (L1, L2) connected by edges.
Key Facts
NodeA single element in a binary tree that holds data.
RootThe topmost node in a binary tree from which all nodes descend.
ParentA node that has one or two child nodes connected below it.
ChildA node that descends from a parent node.
LeafA node with no children, at the end of a branch.
EdgeThe connection between a parent node and a child node.
SubtreeA smaller tree consisting of a node and all its descendants.
DepthThe number of edges from the root node to a given node.
HeightThe number of edges on the longest path from a node to a leaf.
Common Confusions
Thinking the root node is the same as a leaf node.
Thinking the root node is the same as a leaf node. The root node is at the top and has children, while leaf nodes have no children and are at the ends of branches.
Believing a node can have more than two children in a binary tree.
Believing a node can have more than two children in a binary tree. By definition, a binary tree node can have at most two children, called left and right child.
Mixing up depth and height measurements.
Mixing up depth and height measurements. Depth counts edges from the root down to a node; height counts edges from a node down to its farthest leaf.
Summary
A binary tree is made of nodes connected by edges, starting from a root node.
Parent nodes connect to child nodes, and leaf nodes have no children.
Depth measures distance from the root, while height measures distance to the farthest leaf.