Trees Terminology
Trees Terminology
A tree is a hierarchical data structure that consists of nodes connected by edges. It is a fundamental
structure used in various computer science applications like databases, file systems, network protocols,
and many algorithms.
1. Node
A node is a fundamental part of a tree. Each node stores some data and can have connections (edges) to
other nodes. The key components of a node are:
2. Root
The root is the topmost node in the tree. It has no parent, and every other node in the tree is a
descendant of the root. In most diagrams, the root is drawn at the top, but conceptually it is the start of
the hierarchy.
3. Edge
An edge is the connection between two nodes. In a tree, an edge always connects a parent to a child.
The edges represent the relationships between the nodes.
4. Child
A node that is directly connected to another node when moving away from the root is called a child of
that node. A node can have multiple children but only one parent.
5. Parent
A node that has one or more children is called a parent of those children. The parent node is the direct
predecessor of its child nodes.
6. Siblings
Nodes that share the same parent are called siblings. Siblings are at the same level in the tree hierarchy.
A leaf is a node that has no children. It is the end of a path in the tree, and it is also called a terminal
node.
8. Internal Node
A node that has at least one child is called an internal node. It is not a leaf, but any node in the tree that
is neither the root nor a leaf is called an internal node.
9. Subtree
A subtree is a part of a tree that consists of a node and all of its descendants. Any node in a tree can be
considered the root of a subtree.
The height of a node is the number of edges on the longest path from that node to a leaf. A leaf node
has a height of 0.
The depth of a node is the number of edges from the root to that node. The root node has a depth of 0.
The level of a node refers to its depth in the tree. All nodes at the same depth have the same level. The
root is at level 0, its children are at level 1, and so on.
The degree of a node is the number of children it has. A leaf node has a degree of 0.
14. Path
A path is a sequence of nodes and edges connecting a node to its descendant. A path from one node to
another is unique in a tree.
• Ancestor: A node is an ancestor of another node if it exists in the path from the root to that
node. The root is an ancestor of all nodes.
• Descendant: A node is a descendant of another node if it can be reached by moving down from
that node.
A binary tree is a tree in which every node has at most two children, referred to as the left child and the
right child. Many specialized tree structures are based on binary trees.
A tree is considered balanced if the heights of its subtrees differ by at most one for every node. Balanced
trees are preferred in algorithms and data structures (like AVL or Red-Black trees) because they ensure
efficient operations.
A full binary tree is a binary tree in which every node has either 0 or 2 children. No node has only one
child.
A complete binary tree is a binary tree in which all levels are fully filled except possibly the last, and the
last level is filled from left to right.
20. Binary Search Tree (BST)
• All the nodes in the left subtree have values less than the node.
• All the nodes in the right subtree have values greater than the node. This property makes BSTs
useful for searching, insertion, and deletion operations.
mathematica
Copy code
A (Root)
/ \
B C
/\ /\
D E F G
• D, E, F, and G are siblings because they share the same parent (B or C).
Summary
• The root is the top node, and leaves are nodes with no children.
• Trees have key properties like height, depth, and degree, which describe the position and
structure of nodes.
• Special trees (e.g., binary trees, balanced trees, and binary search trees) are common for specific
applications.