SlideShare a Scribd company logo
2
Most read
5
Most read
12
Most read
BINARY SEARCH
TREE
DEFINITION:
 Binary search tree is node based binary tree data
structure.
Each node has a key and an associated value.
27
14
10 19
35
4231
Node:
A node having some data, references to its left and right
child nodes.
struct nodes
{
int data;
struct node *leftChild;
struct node *rightChild;
};
BASIC OPERATION:
Search
Insert
Pre-ordetraversal
In-order traversal
Postordertraversal
OPERATION ON BINARY SEARCH TREE:
Search − Searches an element in a tree.
Insert − Inserts an element in a tree.
Pre-order Traversal − Traverses a tree in a pre-order
manner.
In-order Traversal − Traverses a tree in an in-order
manner.
Post-order Traversal − Traverses a tree in a post-order
manner.
SEARCH:
Start searching from the root node. Then if the data is
less than the key value, search for the element in the left
subtree. search for the element in the rightsubtree.
EG:
search(ptnode root, int key)
{
if (!root) return NULL;
if (key == root->key) return root;
if (key < root->key)
return search(root->left,key);
return search(root->right,key);
}
INSERT:
A new key is always inserted at leaf. We start searching a
key from root till we hit a leaf node.
EG:
void insert(TreeNode<ItemType>*& tree, ItemType item)
{
if(tree == NULL)
{
tree = new TreeNode<ItemType>;
tree->right = NULL;
tree->left = NULL;
tree->info = item;
}
else if(item < tree->info)
Insert(tree->left, item);
else
Insert(tree->right, item);
}
9
7
5
4 6 8
10
10
10>7
10>9
INSERT AN ELEMENT IN THE LEAF
NODE
INORDER TRAVERSAL:
Visit the nodes in the left subtree, then visit the root of
the tree, then visit the nodes in the right subtree .
Inorder(tree)
If tree is not NULL
Inorder(Left(tree))
Visit Info(tree)
Inorder(Right(tree))
IN ORDER
10
‘J’
‘E’
‘A
’
‘H
’
‘T
’
‘M’
‘Y
’
tre
e
Visit left subtree first Visit right subtree last
Visit second
PREORDER:
Visit the root of the tree first, then visit the nodes in the
left subtree, then visit the nodes in the right subtree
Preorder(tree)
If tree is not NULL
Visit Info(tree)
Preorder(Left(tree))
Preorder(Right(tree))
PREORDER
12
‘J’
‘E’
‘A
’
‘H
’
‘T
’
‘M’
‘Y
’
tre
e
Visit left subtree second Visit right subtree last
Visit first
POST ORDER:
Visit the nodes in the left subtree first, then visit the
nodes in the right subtree, then visit the root of the tree
Postorder(tree)
If tree is not NULL
Postorder(Left(tree))
Postorder(Right(tree))
Visit Info(tree)
POST ORDER:
POST ORDER
14
‘J’
‘E’
‘A
’
‘H
’
‘T
’
‘M’
‘Y
’
tre
e
Visit left subtree first Visit right subtree second
THANK YOU

More Related Content

PPTX
Binary Tree in Data Structure
PPT
Binary tree
PPTX
Binary trees1
PPTX
Different types of Linked list.
PPT
1.5 binary search tree
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
PPTX
Binary Search Tree
Binary Tree in Data Structure
Binary tree
Binary trees1
Different types of Linked list.
1.5 binary search tree
Trees, Binary Search Tree, AVL Tree in Data Structures
Binary Search Tree

What's hot (20)

PPTX
Trees (data structure)
PPT
Data Structure and Algorithms Binary Search Tree
PPT
Red black tree
PPTX
Tree in data structure
PPT
Queue implementation
PPTX
Linear and Binary search
PPT
Abstract data types
PPTX
Binary Search Tree in Data Structure
PPSX
data structure(tree operations)
PPT
B trees in Data Structure
PPT
Binary search tree(bst)
PPTX
Priority Queue in Data Structure
PPTX
Insertion sort algorithm power point presentation
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
PDF
UNIT I LINEAR DATA STRUCTURES – LIST
PPTX
Deque and its applications
PPSX
Data Structure (Queue)
PDF
Binary search tree operations
PPTX
Linked List
PDF
Searching and Sorting Techniques in Data Structure
Trees (data structure)
Data Structure and Algorithms Binary Search Tree
Red black tree
Tree in data structure
Queue implementation
Linear and Binary search
Abstract data types
Binary Search Tree in Data Structure
data structure(tree operations)
B trees in Data Structure
Binary search tree(bst)
Priority Queue in Data Structure
Insertion sort algorithm power point presentation
Data Structures - Lecture 9 [Stack & Queue using Linked List]
UNIT I LINEAR DATA STRUCTURES – LIST
Deque and its applications
Data Structure (Queue)
Binary search tree operations
Linked List
Searching and Sorting Techniques in Data Structure
Ad

Similar to Binary search tree (20)

PPTX
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
PDF
Unit iv data structure-converted
PPTX
Binary tree
PPTX
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
PDF
Treeeeeeeeeeeeeeeeereeeeeeeeeeeeeeee.pdf
PDF
Tree and binary tree
PDF
PPTX
Lecture_10 - Revised.pptx
DOCX
Biary search Tree.docx
PPT
PPTX
PPT
Algorithm and Data Structure - Binary Trees
PDF
Binary Tree - Algorithms
PPTX
Binary Search Tree.pptx
PDF
Tree Data Structure by Daniyal Khan
PDF
Lecture notes data structures tree
PPTX
Binary search tree
PPT
BinarySearchTrees.ppt
PPT
BinarySearchTrees.ppt
PPT
BinarySearchTrees.ppt
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
Unit iv data structure-converted
Binary tree
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
Treeeeeeeeeeeeeeeeereeeeeeeeeeeeeeee.pdf
Tree and binary tree
Lecture_10 - Revised.pptx
Biary search Tree.docx
Algorithm and Data Structure - Binary Trees
Binary Tree - Algorithms
Binary Search Tree.pptx
Tree Data Structure by Daniyal Khan
Lecture notes data structures tree
Binary search tree
BinarySearchTrees.ppt
BinarySearchTrees.ppt
BinarySearchTrees.ppt
Ad

More from Kousalya M (6)

PPTX
Function template
PPTX
Class template
PPTX
Binary search tree deletion
PPTX
Red black trees and their properties
PPTX
Red black tree insertion
PPTX
Structures in c programming
Function template
Class template
Binary search tree deletion
Red black trees and their properties
Red black tree insertion
Structures in c programming

Recently uploaded (20)

PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PPTX
Introduction to Building Materials
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
Computing-Curriculum for Schools in Ghana
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
1_English_Language_Set_2.pdf probationary
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
Trump Administration's workforce development strategy
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Unit 4 Computer Architecture Multicore Processor.pptx
Introduction to Building Materials
Chinmaya Tiranga quiz Grand Finale.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Computing-Curriculum for Schools in Ghana
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Hazard Identification & Risk Assessment .pdf
History, Philosophy and sociology of education (1).pptx
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
1_English_Language_Set_2.pdf probationary
LDMMIA Reiki Yoga Finals Review Spring Summer
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
What if we spent less time fighting change, and more time building what’s rig...
Paper A Mock Exam 9_ Attempt review.pdf.
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Trump Administration's workforce development strategy

Binary search tree