Data Structures Tree (Types & Algorithms)
Knowing the terminology and properties of trees will help you better comprehend algorithms that use
trees as their primary data structure.
Tree Data Structure
A tree data structure is a hierarchical structure where each node can have a maximum of two child
nodes. A tree can be classified into three types: binary, nary, and search trees. In this post, we will focus
on binary and search trees.
Binary Tree
A binary tree is a type of tree data structure where each node can have at most two child nodes, which
are referred to as the left child and the right child. A binary tree can be either a full or a complete binary
tree.
Full Binary Tree
A full binary tree is a binary tree where every node, except possibly the leaf nodes, has exactly two child
nodes. To create a full bundled tree, a dummy node is added to the tree.
Tree Implementation
Tree data structures can be implemented using either a link list or an array. Each node in the tree
contains the left, right, and data parts.
Linked List Implementation
In a linked list implementation, each node contains the left, right, and data parts. The left part points to
the left child node, the right part points to the right child node, and the data part stores the value of the
node.
Array Implementation
Knowing the terminology and properties of trees will help you better comprehend algorithms that use
trees as their primary data structure.
Tree Data Structure
A tree data structure is a hierarchical structure where each node can have a maximum of two child
nodes. A tree can be classified into three types: binary, nary, and search trees. In this post, we will focus
on binary and search trees.
Binary Tree
A binary tree is a type of tree data structure where each node can have at most two child nodes, which
are referred to as the left child and the right child. A binary tree can be either a full or a complete binary
tree.
Full Binary Tree
A full binary tree is a binary tree where every node, except possibly the leaf nodes, has exactly two child
nodes. To create a full bundled tree, a dummy node is added to the tree.
Tree Implementation
Tree data structures can be implemented using either a link list or an array. Each node in the tree
contains the left, right, and data parts.
Linked List Implementation
In a linked list implementation, each node contains the left, right, and data parts. The left part points to
the left child node, the right part points to the right child node, and the data part stores the value of the
node.
Array Implementation