Tree Data Structure
Tree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes.
Table of Content
- What is Tree Data Structure?
- Terminologies In Tree Data Structure
- Types of Tree Data Structure
- Applications of Tree Data Structure
- Basics of Tree Data Structure
- Basic Operations on Tree Data Structure
- n-ary or Generic Tree
- Binary Tree
- Binary Search Tree
- Ternary Search Tree
- AVL Tree
- B+ Tree
- Red-Black Tree
- Other types of Trees
- Trees vs other Data Structures
- Comparison among different Tree Data Structures
- Problems based on Tree Data Structure
What is Tree Data Structure?
A tree data structure is a hierarchical structure that is used to represent and organize data in a way that is easy to navigate and search. It is a collection of nodes that are connected by edges and has a hierarchical relationship between the nodes.
The topmost node of the tree is called the root, and the nodes below it are called the child nodes. Each node can have multiple child nodes, and these child nodes can also have their own child nodes, forming a recursive structure.
Terminologies In Tree Data Structure
- Parent Node: The node which is a predecessor of a node is called the parent node of that node. {B} is the parent node of {D, E}.
- Child Node: The node which is the immediate successor of a node is called the child node of that node. Examples: {D, E} are the child nodes of {B}.
- Root Node: The topmost node of a tree or the node which does not have any parent node is called the root node. {A} is the root node of the tree. A non-empty tree must contain exactly one root node and exactly one path from the root to all other nodes of the tree.
- Leaf Node or External Node: The nodes which do not have any child nodes are called leaf nodes. {K, L, M, N, O, P, G} are the leaf nodes of the tree.
- Ancestor of a Node: Any predecessor nodes on the path of the root to that node are called Ancestors of that node. {A,B} are the ancestor nodes of the node {E}
- Descendant: A node x is a descendant of another node y if and only if y is an ancestor of y.
- Sibling: Children of the same parent node are called siblings. {D,E} are called siblings.
- Level of a node: The count of edges on the path from the root node to that node. The root node has level 0.
- Internal node: A node with at least one child is called Internal Node.
- Neighbor of a Node: Parent or child nodes of that node are called neighbors of that node.
- Subtree: Any node of the tree along with its descendant.
Types of Tree Data Structure
- Binary tree: In a binary tree, each node can have a maximum of two children linked to it. Some common types of binary trees include full binary trees, complete binary trees, balanced binary trees, and degenerate or pathological binary trees.
- Ternary Tree: A Ternary Tree is a tree data structure in which each node has at most three child nodes, usually distinguished as “left”, “mid” and “right”.
- N-ary Tree or Generic Tree: Generic trees are a collection of nodes where each node is a data structure that consists of records and a list of references to its children(duplicate references are not allowed). Unlike the linked list, each node stores the address of multiple nodes.
Applications of Tree Data Structure
- File System: This allows for efficient navigation and organization of files.
- Data Compression: Huffman coding is a popular technique for data compression that involves constructing a binary tree where the leaves represent characters and their frequency of occurrence. The resulting tree is used to encode the data in a way that minimizes the amount of storage required.
- Compiler Design: In compiler design, a syntax tree is used to represent the structure of a program.
- Database Indexing: B-trees and other tree structures are used in database indexing to efficiently search for and retrieve data.
Basics of Tree Data Structure
Basic Operations on Tree Data Structure
n-ary or Generic Tree
Binary Tree
- Introduction to Binary Tree – Data Structure and Algorithm Tutorials
- Properties of Binary Tree
- Types of Binary Tree
- Applications, Advantages and Disadvantages of Binary Tree
- Binary Tree (Array implementation)
- Level Order Tree Traversal
- Inorder Traversal of Binary Tree
- Preorder Traversal of Binary Tree
- Postorder Traversal of Binary Tree
- Insertion in a Binary Tree
- Deletion in a Binary Tree
- Enumeration of Binary Trees
Binary Search Tree
- Introduction to Binary Search Tree – Data Structure and Algorithm Tutorials
- Applications of BST
- Application, Advantages and Disadvantages of Binary Search Tree
- Insertion in Binary Search Tree
- Searching in Binary Search Tree
- Binary Search Tree (BST) Traversals – Inorder, Preorder, Post Order
- Deletion in Binary Search Tree
Ternary Search Tree
AVL Tree
- AVL Tree Data Structure
- What is AVL Tree | AVL Tree meaning
- Insertion in an AVL Tree
- Deletion in an AVL Tree
- Weak AVL or Rank Balanced Trees
- Insertion, Searching and Deletion in AVL trees containing a parent node pointer
- AVL with duplicate keys
- Count greater nodes in AVL tree
- How to insert Strings into an AVL Tree
- Minimum number of nodes in an AVL Tree with given height
- Optimal sequence for AVL tree insertion (without any rotations)
- Different shapes of AVL possible at height h
B Tree
B+ Tree
Red-Black Tree
Other types of Trees
- Ternary Tree:
- Interval Tree:
- 2-3-4 Tree:
Trees vs other Data Structures
Comparison among different Tree Data Structures
- Difference between General tree and Binary tree
- Difference between Binary Tree and Binary Search Tree
- Difference between Binary tree and B-tree
- Difference between B tree and B+ tree
- Difference between Full and Complete Binary Tree
- Difference between Binary Search Tree and AVL Tree
- Red Black Tree vs AVL Tree
Problems based on Tree Data Structure
Quick Links:
- Practice problems on Trees
- Videos on Trees
- Quizzes on Tree
Contact Us