Open In App

Tree Data Structure

Last Updated : 02 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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.

tree-data-structure-banners-(2)

What is Tree Data Structure?

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

  1. Height of Tree
  2. Height and Depth of Node
  3. Level of a Given Node in Tree
  4. Search a Node in Tree
  5. Find the Parent of a Node
  6. Diameter of a Tree
  7. Find all Leaf nodes
  8. Find Siblings of a Node
  9. Find Children of a Node
  10. Tree Traversals (Inorder, Preorder and Postorder)

n-ary or Generic Tree

  1. Generic Trees(N-ary Trees)
  2. What is Generic Tree or N-ary Tree
  3. Depth of an N-ary Tree
  4. Mirror of n-ary Tree
  5. Diameter of an N-ary Tree
  6. Level Order Traversal of N-ary Tree
  7. Sum of all elements of N-ary Tree
  8. Serialize and Deserialize an N-ary Tree

Binary Tree

  1. Introduction to Binary Tree – Data Structure and Algorithm Tutorials
  2. Properties of Binary Tree
  3. Types of Binary Tree
  4. Applications, Advantages and Disadvantages of Binary Tree
  5. Binary Tree (Array implementation)
  6. Level Order Tree Traversal
  7. Inorder Traversal of Binary Tree
  8. Preorder Traversal of Binary Tree
  9. Postorder Traversal of Binary Tree
  10. Insertion in a Binary Tree
  11. Deletion in a Binary Tree
  12. Enumeration of Binary Trees

Binary Search Tree

  1. Introduction to Binary Search Tree – Data Structure and Algorithm Tutorials
  2. Applications of BST
  3. Application, Advantages and Disadvantages of Binary Search Tree
  4. Insertion in Binary Search Tree
  5. Searching in Binary Search Tree
  6. Binary Search Tree (BST) Traversals – Inorder, Preorder, Post Order
  7. Deletion in Binary Search Tree

Ternary Search Tree

  1. Ternary Search Tree
  2. Ternary Search Tree meaning & definition in DSA
  3. Ternary Search Tree (Deletion)
  4. How to implement text Auto-complete feature using Ternary Search Tree
  5. Longest word in ternary search tree

AVL Tree

  1. AVL Tree Data Structure
  2. What is AVL Tree | AVL Tree meaning
  3. Insertion in an AVL Tree
  4. Deletion in an AVL Tree
  5. Weak AVL or Rank Balanced Trees
  6. Insertion, Searching and Deletion in AVL trees containing a parent node pointer
  7. AVL with duplicate keys
  8. Count greater nodes in AVL tree
  9. How to insert Strings into an AVL Tree
  10. Minimum number of nodes in an AVL Tree with given height
  11. Optimal sequence for AVL tree insertion (without any rotations)
  12. Different shapes of AVL possible at height h

B Tree

  1. Introduction of B-Tree
  2. What is B-Tree? | B-Tree meaning
  3. Insert Operation in B-Tree
  4. Delete Operation in B-Tree
  5. B-Tree Insert without aggressive splitting

B+ Tree

  1. Introduction of B+ Tree
  2. What is B+ Tree | B+ Tree meaning
  3. Insertion in a B+ tree
  4. Deletion in B+ Tree

Red-Black Tree

  1. Introduction to Red-Black Tree
  2. Red-Black Tree Definition & Meaning in DSA
  3. Insertion in Red-Black Tree
  4. Red-Black Trees | Top-Down Insertion
  5. Deletion in Red-Black Tree
  6. Applications, Advantages, and Disadvantages of Red-Black Tree

Other types of Trees

Trees vs other Data Structures

  1. Difference between graph and tree
  2. Comparison between Heap and Tree
  3. What is the difference between Heap and Red-Black Tree?
  4. Difference between Binary Search Tree and Binary Heap
  5. Difference between Stack and Tree
  6. Difference between an array and a tree

Comparison among different Tree Data Structures

  1. Difference between General tree and Binary tree
  2. Difference between Binary Tree and Binary Search Tree
  3. Difference between Binary tree and B-tree
  4. Difference between B tree and B+ tree
  5. Difference between Full and Complete Binary Tree
  6. Difference between Binary Search Tree and AVL Tree
  7. Red Black Tree vs AVL Tree

Problems based on Tree Data Structure

Problems

Difficulty Level

Solve

Height of Binary Tree

Easy

Solve
Determine if two trees are identical

Easy

Solve
Mirror tree

Easy

Solve
Symmetric Tree

Easy

Solve
Diameter of tree

Easy

Solve
Checked for Balanced tree

Easy

Solve
Children Sum Parent

Easy

Solve
Check for BST

Easy

Solve
Array to BST

Easy

Solve
Largest value in each level of binary tree

Easy

Solve
Maximum GCD of siblings of a binary tree

Easy

Solve
Zigzag Tree Traversal

Easy

Solve
Inorder Successor in BST

Easy

Solve
Kth Largest Element in a BST

Easy

Solve
Check if subtree

Medium

Solve
Single Valued Subtree

Medium

Solve
Unique BSTs

Medium

Solve
Inorder Traversal (iterative)

Medium

Solve
Preorder Traversal (iterative)

Medium

Solve
Postorder Traversal(iterative)

Medium

Solve
Vertical Traversal of a Binary Tree

Medium

Solve
Boundary Traversal

Medium

Solve
Construct Binary Tree from Parent array

Medium

Solve
Construct Binary Tree from Preorder and Inorder Traversal

Medium

Solve
Preorder Traversal and BST

Medium

Solve
Construct tree from preorder traversal

Medium

Solve
Minimum distance between two given nodes

Medium

Solve
Maximum sum leaf to root path

Medium

Solve
Odd Even Level Difference

Medium

Solve
Lowest Common Ancestor of a Binary Tree

Medium

Solve
Ancestors in Binary Tree

Medium

Solve
Remove BST keys outside the given range

Medium

Solve
Pair with given target in BST

Medium

Solve
Sum Tree

Medium

Solve
BST to greater sum tree

Medium

Solve
BST to max heap

Medium

Solve
Clone binary tree with random pointer

Medium

Solve
Maximum sum of non adjacent nodes

Medium

Solve
Largest BST in a Binary Tree

Medium

Solve
Extreme nodes in alternate order

Medium

Solve
Connect nodes at same level

Hard

Solve
Nodes at given distance in a Binary Tree

Hard

Solve
Sorted Linked List to BST

Hard

Solve
Binary Tree to Doubly Linked List

Hard

Solve
Maximum sum path between two leaf nodes

Hard

Solve
K-Sum Paths

Hard

Solve
Number of turns in a binary tree

Hard

Solve
Merge two BST’s

Hard

Solve
Fixing two nodes of a BST

Hard

Solve
Burn Binary Tree

Hard

Solve

Quick Links:



Previous Article
Next Article

Similar Reads

Static Data Structure vs Dynamic Data Structure
Data structure is a way of storing and organizing data efficiently such that the required operations on them can be performed be efficient with respect to time as well as memory. Simply, Data Structure are used to reduce complexity (mostly the time complexity) of the code. Data structures can be two types : 1. Static Data Structure 2. Dynamic Data
4 min read
Tango Tree Data Structure
INTRODUCTION:' Tango Tree is a data structure for efficient dynamic connectivity and range minimum/maximum query on a set of elements. It is a type of balanced binary search tree that uses finger trees as the underlying data structure to achieve fast and efficient operations. The Tango Tree is designed to support both fast insertions and deletions
4 min read
Merge Sort Tree with point update using Policy Based Data Structure
A Merge Sort Tree (MST) is a data structure that allows for efficient querying of the number of elements less than or equal to a certain value in a range of an array. It is built using a divide-and-conquer approach similar to the merge sort algorithm, where the array is recursively divided into two halves and a tree is constructed to represent the
7 min read
AVL Tree Data Structure
An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of the node. The AVL tree is named after its inventors, Georgy
3 min read
Applications of tree data structure
What is Tree Data Structure?A tree is a type of data structure that represents a hierarchical relationship between data elements, called nodes. The top node in the tree is called the root, and the elements below the root are called child nodes. Each child node may have one or more child nodes of its own, forming a branching structure. The nodes at
4 min read
Introduction to Splay tree data structure
Splay tree is a self-adjusting binary search tree data structure, which means that the tree structure is adjusted dynamically based on the accessed or inserted elements. In other words, the tree automatically reorganizes itself so that frequently accessed or inserted elements become closer to the root node. The splay tree was first introduced by Da
15+ min read
Introduction to Finger search tree Data Structure
A finger search tree is a data structure that is designed to allow for efficient search and access of data in a set or a sequence. It is a type of binary search tree that uses a "finger" or a reference to a particular element in the tree to quickly find and retrieve other elements. In this article, we will explore the types, advantages, disadvantag
15+ min read
Binary Tree Data Structure
A Binary Tree Data Structure is a hierarchical data structure in which each node has at most two children, referred to as the left child and the right child. It is commonly used in computer science for efficient storage and retrieval of data, with various operations such as insertion, deletion, and traversal. Introduction: Introduction to Binary Tr
4 min read
Introduction to Tree Data Structure
Tree data structure is a specialized data structure to store data in hierarchical manner. It is used to organize and store data in the computer to be used more effectively. It consists of a central node, structural nodes, and sub-nodes, which are connected via edges. We can also say that tree data structure has roots, branches, and leaves connected
15+ min read
Is array a Data Type or Data Structure?
What is Data Type? In computer programming, a data type is a classification of data that determines the type of values that can be stored, manipulated, and processed. It tells the computer what kind of data a particular variable or constant can hold, and what operations can be performed on that data. Common data types include integers, floating-poi
8 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg