SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
BIRLA INSTITUTE OF TECHNOLOGY
MESRA,
JAIPUR CAMPUS
TOPIC:- BINARY SEARCH TREE
NAME:- TARUN TIWARI
ROLL NO.:- MCA/25007/18
CLASS:- MCA 2ND SEM.
BINARY SEARCH TREE
• In Binary Search Tree, all the left subtree elements
should be less than root data and all the right
subtree elements should be greater than root data.
This is called binary search tree property.
• This property should be satisfied at every node in
the tree.
Examples
Binary
search trees
Not a binary
search tree
5
10
30
2 25 45
5
10
45
2 25 30
5
10
30
2
25
45
Data
NODE
LEFT CHILD RIGHT CHILD
Struct node {
int data;
struct node *leftChild;
struct node *rightChild;
};
STRUCTURE OF TREE NODE
SEARCHING BINARY SEARCH TREE
Example: Suppose T is the tree being searched:
• If we are searching for 15, then we are done.
• If we are searching for a key < 15, then we should search in the left
subtree.
• If we are searching for a key > 15, then we should search in the
right subtree.
Binary Search Tree in Data Structure
BINARY SEARCH TREE ALGORITHM
SearchElement (TREE,VAL)
Step 1: If Tree-> DATA=VAL OR TREE=NULL
RETURN TREE
ELSE
IF VAL < TREE -> DATA
RETURN SearchElement(TREE->LEFT,VAL)
ELSE
RETURN SearchElement(TREE->RIGHT,VAL)
[END OF IF]
[END OF IF]
Step 2 : EXIT
INSERTION BINARY SEARCH TREE
• IMPLEMENTING INSERTION RECURSIVELY
BINARY SEARCH TREE INSERTION
ALGORITHM
INSERT (TREE,VAL)
Step 1: IF TREE= NULL
Allocate memory for TREE
SET TREE -> DATA=VAL
SET TREE ->LEFT = TREE->RIGHT =NULL
ELSE
IF VAL < TREE->DATA
INSERT (TREE->LEFT , VAL)
ELSE
INSERT (TREE->RIGHT , VAL)
[END OF IF]
[END OF IF]
Step 2: EXIT
DELETION BINARY SEARCH TREE
Case 1: the node is a leaf Delete it immediately
Case 2: the node has one child
Adjust a pointer from the parent to bypass that
node
Case 3: the node has 2 children
Replace the key of that node with the minimum
element at the right subtree
COMPLEXITY IN BST
Operation Average Worst Case Best
Case
Search O(log n) O(n) O(1)
Insertion O(log n) O(n) O(1)
Deletion O(log n) O(n) O(1)
APPLICATIONS OF BST
• Used in many search applications where data is constantly
entering/leaving, such as the map and set objects in many
languages' libraries.
• Storing a set of names, and being able to lookup based on a prefix
of the name. (Used in internet routers.)
• Storing a path in a graph, and being able to reverse any subsection
of the path in O(log n) time. (Useful in travelling salesman
problems).
• Finding square root of given number
• allows you to do range searches efficiently.
THANK YOU

More Related Content

What's hot (20)

PPTX
THREADED BINARY TREE AND BINARY SEARCH TREE
Siddhi Shrivas
 
PPT
Searching algorithms
Trupti Agrawal
 
PPTX
Nikhat b+ trees ppt
Nikihat Maniyar
 
PDF
Binary tree
Rajendran
 
PPTX
Tree Traversal
Md. Israil Fakir
 
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
PPTX
Doubly Linked List
V.V.Vanniaperumal College for Women
 
PPTX
SQL Basics
Hammad Rasheed
 
PPTX
linked list in data structure
shameen khan
 
PPTX
Red black tree in data structure
Vrushali Dhanokar
 
PPTX
B+ tree intro,uses,insertion and deletion
HAMID-50
 
PPTX
Data structure tries
Md. Naim khan
 
PPTX
Binary search tree
Kousalya M
 
PPT
BINARY SEARCH TREE
ER Punit Jain
 
PPTX
Linklist
SHEETAL WAGHMARE
 
PPTX
B and B+ tree
Ashish Arun
 
PPTX
Trees in data structures
ASairamSairam1
 
THREADED BINARY TREE AND BINARY SEARCH TREE
Siddhi Shrivas
 
Searching algorithms
Trupti Agrawal
 
Nikhat b+ trees ppt
Nikihat Maniyar
 
Binary tree
Rajendran
 
Tree Traversal
Md. Israil Fakir
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
SQL Basics
Hammad Rasheed
 
linked list in data structure
shameen khan
 
Red black tree in data structure
Vrushali Dhanokar
 
B+ tree intro,uses,insertion and deletion
HAMID-50
 
Data structure tries
Md. Naim khan
 
Binary search tree
Kousalya M
 
BINARY SEARCH TREE
ER Punit Jain
 
B and B+ tree
Ashish Arun
 
Trees in data structures
ASairamSairam1
 

Similar to Binary Search Tree in Data Structure (20)

PPTX
8.binry search tree
Chandan Singh
 
PPTX
Binary tree
Maria Saleem
 
PPTX
Lecture 9 data structures and algorithms
Aakash deep Singhal
 
PPT
Lecture 7-BinarySearchTrees.ppt
DrBashirMSaad
 
PDF
BinarySearchTree-bddicken
Benjamin Dicken
 
PPTX
BINARY TREE data structure and algorithm-1.pptx
rathoreravindra2112
 
PPTX
Binary search tree definition operation.pptx
jeevananandk28
 
PPTX
Binary Search Tree In Python.pptx
RohanThota3
 
PPTX
BST binary search tree with tree traversals.pptx
VarshithaKolla
 
PPTX
Binary Search Tree
Eyakub Sorkar
 
PPT
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
sumitbardhan
 
PDF
Binary search tree with pre-order inorder and postorder
VarshithaKolla
 
PDF
bst-copy-171118141913.pdf
ControlUrgentSecurit
 
PDF
binarysearchtreeindatastructures-200604055006 (1).pdf
ajajkhan16
 
PPTX
Binary Search Tree
Abhishek L.R
 
PDF
Binary Search Tree (BST) Explained Step-by-Step
scientistfromuet
 
PPT
Binary search tree in data structures
chauhankapil
 
PPT
Chapter 9 ds
Hanif Durad
 
PPTX
Binary Search Tree
INAM352782
 
PPTX
DAA PPT.pptx
INAM352782
 
8.binry search tree
Chandan Singh
 
Binary tree
Maria Saleem
 
Lecture 9 data structures and algorithms
Aakash deep Singhal
 
Lecture 7-BinarySearchTrees.ppt
DrBashirMSaad
 
BinarySearchTree-bddicken
Benjamin Dicken
 
BINARY TREE data structure and algorithm-1.pptx
rathoreravindra2112
 
Binary search tree definition operation.pptx
jeevananandk28
 
Binary Search Tree In Python.pptx
RohanThota3
 
BST binary search tree with tree traversals.pptx
VarshithaKolla
 
Binary Search Tree
Eyakub Sorkar
 
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
sumitbardhan
 
Binary search tree with pre-order inorder and postorder
VarshithaKolla
 
bst-copy-171118141913.pdf
ControlUrgentSecurit
 
binarysearchtreeindatastructures-200604055006 (1).pdf
ajajkhan16
 
Binary Search Tree
Abhishek L.R
 
Binary Search Tree (BST) Explained Step-by-Step
scientistfromuet
 
Binary search tree in data structures
chauhankapil
 
Chapter 9 ds
Hanif Durad
 
Binary Search Tree
INAM352782
 
DAA PPT.pptx
INAM352782
 
Ad

More from Meghaj Mallick (20)

PPT
24 partial-orderings
Meghaj Mallick
 
PPTX
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
PPTX
Introduction to Software Testing
Meghaj Mallick
 
PPTX
Introduction to System Programming
Meghaj Mallick
 
PPTX
MACRO ASSEBLER
Meghaj Mallick
 
PPTX
Icons, Image & Multimedia
Meghaj Mallick
 
PPTX
Project Tracking & SPC
Meghaj Mallick
 
PPTX
Peephole Optimization
Meghaj Mallick
 
PPTX
Routing in MANET
Meghaj Mallick
 
PPTX
Macro assembler
Meghaj Mallick
 
PPTX
Architecture and security in Vanet PPT
Meghaj Mallick
 
PPTX
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
PPTX
Text Mining of Twitter in Data Mining
Meghaj Mallick
 
PPTX
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
PPTX
Software Development Method
Meghaj Mallick
 
PPTX
Secant method in Numerical & Statistical Method
Meghaj Mallick
 
PPTX
Motivation in Organization
Meghaj Mallick
 
PPTX
Communication Skill
Meghaj Mallick
 
PPT
Partial-Orderings in Discrete Mathematics
Meghaj Mallick
 
PPTX
Hashing In Data Structure
Meghaj Mallick
 
24 partial-orderings
Meghaj Mallick
 
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
Introduction to Software Testing
Meghaj Mallick
 
Introduction to System Programming
Meghaj Mallick
 
MACRO ASSEBLER
Meghaj Mallick
 
Icons, Image & Multimedia
Meghaj Mallick
 
Project Tracking & SPC
Meghaj Mallick
 
Peephole Optimization
Meghaj Mallick
 
Routing in MANET
Meghaj Mallick
 
Macro assembler
Meghaj Mallick
 
Architecture and security in Vanet PPT
Meghaj Mallick
 
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
Text Mining of Twitter in Data Mining
Meghaj Mallick
 
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
Software Development Method
Meghaj Mallick
 
Secant method in Numerical & Statistical Method
Meghaj Mallick
 
Motivation in Organization
Meghaj Mallick
 
Communication Skill
Meghaj Mallick
 
Partial-Orderings in Discrete Mathematics
Meghaj Mallick
 
Hashing In Data Structure
Meghaj Mallick
 
Ad

Recently uploaded (17)

PPTX
2025-07-06 Abraham 06 (shared slides).pptx
Dale Wells
 
PPTX
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
PPTX
some leadership theories MBA management.pptx
rkseo19
 
PPTX
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
PPTX
AI presentation for everyone in every fields
dodinhkhai1
 
PPTX
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
PDF
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
PDF
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
PDF
The Family Secret (essence of loveliness)
Favour Biodun
 
PPTX
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
PDF
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
PDF
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PDF
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PPTX
presentation on legal and regulatory action
raoharsh4122001
 
PPTX
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
PDF
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
PPTX
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
2025-07-06 Abraham 06 (shared slides).pptx
Dale Wells
 
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
some leadership theories MBA management.pptx
rkseo19
 
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
AI presentation for everyone in every fields
dodinhkhai1
 
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
The Family Secret (essence of loveliness)
Favour Biodun
 
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
presentation on legal and regulatory action
raoharsh4122001
 
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 

Binary Search Tree in Data Structure

  • 1. BIRLA INSTITUTE OF TECHNOLOGY MESRA, JAIPUR CAMPUS TOPIC:- BINARY SEARCH TREE NAME:- TARUN TIWARI ROLL NO.:- MCA/25007/18 CLASS:- MCA 2ND SEM.
  • 2. BINARY SEARCH TREE • In Binary Search Tree, all the left subtree elements should be less than root data and all the right subtree elements should be greater than root data. This is called binary search tree property. • This property should be satisfied at every node in the tree.
  • 3. Examples Binary search trees Not a binary search tree 5 10 30 2 25 45 5 10 45 2 25 30 5 10 30 2 25 45
  • 4. Data NODE LEFT CHILD RIGHT CHILD Struct node { int data; struct node *leftChild; struct node *rightChild; }; STRUCTURE OF TREE NODE
  • 5. SEARCHING BINARY SEARCH TREE Example: Suppose T is the tree being searched: • If we are searching for 15, then we are done. • If we are searching for a key < 15, then we should search in the left subtree. • If we are searching for a key > 15, then we should search in the right subtree.
  • 7. BINARY SEARCH TREE ALGORITHM SearchElement (TREE,VAL) Step 1: If Tree-> DATA=VAL OR TREE=NULL RETURN TREE ELSE IF VAL < TREE -> DATA RETURN SearchElement(TREE->LEFT,VAL) ELSE RETURN SearchElement(TREE->RIGHT,VAL) [END OF IF] [END OF IF] Step 2 : EXIT
  • 10. BINARY SEARCH TREE INSERTION ALGORITHM INSERT (TREE,VAL) Step 1: IF TREE= NULL Allocate memory for TREE SET TREE -> DATA=VAL SET TREE ->LEFT = TREE->RIGHT =NULL ELSE IF VAL < TREE->DATA INSERT (TREE->LEFT , VAL) ELSE INSERT (TREE->RIGHT , VAL) [END OF IF] [END OF IF] Step 2: EXIT
  • 11. DELETION BINARY SEARCH TREE Case 1: the node is a leaf Delete it immediately Case 2: the node has one child Adjust a pointer from the parent to bypass that node
  • 12. Case 3: the node has 2 children Replace the key of that node with the minimum element at the right subtree
  • 13. COMPLEXITY IN BST Operation Average Worst Case Best Case Search O(log n) O(n) O(1) Insertion O(log n) O(n) O(1) Deletion O(log n) O(n) O(1)
  • 14. APPLICATIONS OF BST • Used in many search applications where data is constantly entering/leaving, such as the map and set objects in many languages' libraries. • Storing a set of names, and being able to lookup based on a prefix of the name. (Used in internet routers.) • Storing a path in a graph, and being able to reverse any subsection of the path in O(log n) time. (Useful in travelling salesman problems). • Finding square root of given number • allows you to do range searches efficiently.