Home | Projects | Notes > Data Structures & Algorithms > Trees

Trees

 

Terminology

TermDefinition
NodeA basic unit containing data and links to child nodes.
RootThe topmost node of the tree; has no parent.
ParentA node that has one or more child nodes.
ChildA node that descends from another node.
LeafA node with no children.
Internal NodeA node with at least one child (i.e. not a leaf). Root is also an internal node.
EdgeA connection between a parent and a child node.
PathA sequence of nodes connected by edges.
HeightThe number of edges on the longest path from a node to a leaf.
DepthThe number of edges from the root to a node.
LevelThe depth of a node plus one (root is at level 1).
SubtreeA tree formed from any node and its descendants.
SiblingNodes that share the same parent.
DegreeThe number of children a node has.
Balanced TreeA tree where the height difference between subtrees is minimal.
Binary TreeA tree where each node has at most two children (left and right).

 

Binary Trees

A binary tree is a hierarchical data structure where each node has at most two children: a left child and a right child. It is commonly used to represent structured data like arithmetic expressions, hierarchical relationships, and is the foundation of many search and sorting algorithms.

Common Types

 

array-representation-of-a-complete-binary-tree

 

 

Binary Search Trees

A Binary Search Tree (BST) is a type of binary tree where each node follows a specific ordering rule:

BSTs are widely used for efficient searching, insertion, and deletion, with average-case time complexity of O(log n) for balanced trees.

 

binary-search-tree