SlideShare a Scribd company logo
1 of 28
Download to read offline
PRESENTATION
BINARY SEARCH TREE OPERATION
DEFINATION OF BINARY SEARCH TREE
Binary Search Tree is a node-based binary tree data
structure which has the following properties.
•The left subtree of a node contains only nodes with key
lesser than the node's key.
•The right subtree of a node contains only
node with keys greater than the node's key.
DIAGRAM OF TREE
BASIC OPERATION
•#1) INSERT
•#2)DELETE
•#3)SEARCH
•#4)TRAVERSAL
ADVANTAGES OF BST
•#1)Searching Is Very Efficient
We have all the nodes of BST in a specific order, hence searching for a
particular item is very efficient and faster. This is because we need not search
the entire and compare all nodes.
We just have to compare the root node to the item which we are searching and
then we decide whether we need to search in the left or right subtree.
ADVANTAGES OF BST
•#2) Efficient Working When Compared To
Array And Linked Lists
When we search an item in case of BST, we get rid of half of the left or right
subtree at every step thereby improving the performance of search operation.
This is in contrast to array or linked list in which we need to compare all the
items sequentially to search a particular.
ADVANTAGES OF BST
•#3)Insert And Delete Are Faster
Insert and delete operations also are faster when compared to other data
structures like Linked Lists and Array.
APPLICTION OF BST
• BST is used to implement multilevel indexing in database application.
• BST is also used to implement constructs like a dictionary.
• BST can be used to implement various efficient searching algorithms.
• BST is also used in applications that require a sorted list as input
like the online stories.
• BSTs are also used to evaluate expression using expression trees.
CONCLUTION
Binary search trees(BST) are a variation of the binary tree and are widely used
in the software field. They are also called ordered binary trees as each node in
BST is placed according to a specific order.
Inorder traversal of BST gives us the sorted sequence of items in ascending
order. When BSTs are used for searching, it is very efficient and is done within
no time. BSTs are also used for a variety of application like Huffman's coding,
Multilevel index in database ,etc.
OPERATIONS
SEARCH OPERATION
The Algorithm depends on the property of BST that if each left subtree has
value below root and each right subtree has value above the root.
If the value is below the root, we can say for sure that the value is not in the
right subtree; we need to only search in the left subtree and if the value above
root, we can say for sure that value is not in the left subtree; we need to only
search in the right subtree.
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
INSERT OPERATION
Inserting a value in the correct position is similar to searching because we try to
maintain the rule that the left subtree is lesser than root and the right subtree is
larger than root.
We keep going to either right subtree depending on the value and when we
reach a point left or right subtree is null, we put the new code there.
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
DELETE OPERATION
There are three cases for deleting a node from a binary
search tree.
CASE-1
In the first case, the node to be delete is the leaf node. In such a case, simply
delete the node from the tree.
CASE-2
In the second case, the node to be deleted lies has a single child node.
In such cases follow the step below
1.Replace that node with its child node.
2.Remove the child node from its original position.
Binary search tree operations
CASE-3
• In the third case, the node to be deleted has two children. In such a case
follow the steps below:
1.Get the inorder successor of that.
2.Replace the node with the inorder successor.
3.Remove the inorder successor from its original position.
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
PRESENTED BY:
•Ehsan ul khaliq (F20-BsCS-5004)
•Faisal Shehzad (F20-BsCS-5030)
•Kamran Zafar (F20-BsCS-5039)

More Related Content

What's hot

What's hot (20)

Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Linked List
Linked ListLinked List
Linked List
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Threaded Binary Tree.pptx
Threaded Binary Tree.pptxThreaded Binary Tree.pptx
Threaded Binary Tree.pptx
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Trees
TreesTrees
Trees
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal ppt
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Expression trees
Expression treesExpression trees
Expression trees
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
 
Double ended queue
Double ended queueDouble ended queue
Double ended queue
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 

Similar to Binary search tree operations (20)

Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
DAA PPT.pptx
DAA PPT.pptxDAA PPT.pptx
DAA PPT.pptx
 
Binary trees
Binary treesBinary trees
Binary trees
 
binary search tree
binary search treebinary search tree
binary search tree
 
Database Engine
Database EngineDatabase Engine
Database Engine
 
Binary tree
Binary treeBinary tree
Binary tree
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
 
Unit iv data structure-converted
Unit  iv data structure-convertedUnit  iv data structure-converted
Unit iv data structure-converted
 
Binary search tree.pptx
Binary search tree.pptxBinary search tree.pptx
Binary search tree.pptx
 
nptel 2nd presentation.pptx
nptel 2nd presentation.pptxnptel 2nd presentation.pptx
nptel 2nd presentation.pptx
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
cs702 ppt.ppt
cs702 ppt.pptcs702 ppt.ppt
cs702 ppt.ppt
 
MySQL Indexing
MySQL IndexingMySQL Indexing
MySQL Indexing
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelines
 
Data structure day 6
Data structure day 6Data structure day 6
Data structure day 6
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 

More from Kamran Zafar

DFA Assignment solution.pptx
DFA Assignment solution.pptxDFA Assignment solution.pptx
DFA Assignment solution.pptxKamran Zafar
 
Drones in agri. by eskill india
Drones in agri. by eskill indiaDrones in agri. by eskill india
Drones in agri. by eskill indiaKamran Zafar
 
exercise 3.3 solution /class 12th/ mathcity
exercise 3.3 solution /class 12th/ mathcityexercise 3.3 solution /class 12th/ mathcity
exercise 3.3 solution /class 12th/ mathcityKamran Zafar
 
Lec 1 number systems converted
Lec 1 number systems convertedLec 1 number systems converted
Lec 1 number systems convertedKamran Zafar
 
Lecture 5 binary_codes
Lecture 5 binary_codesLecture 5 binary_codes
Lecture 5 binary_codesKamran Zafar
 
Lecture java continued 1
Lecture java continued 1Lecture java continued 1
Lecture java continued 1Kamran Zafar
 
Lecture java continued
Lecture java continuedLecture java continued
Lecture java continuedKamran Zafar
 
Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)Kamran Zafar
 
digital systems and information
digital systems and informationdigital systems and information
digital systems and informationKamran Zafar
 
02 computing magazine september 2012
02 computing magazine september 201202 computing magazine september 2012
02 computing magazine september 2012Kamran Zafar
 
Learn microsoft word from tayyab riaz
Learn microsoft word from tayyab riaz  Learn microsoft word from tayyab riaz
Learn microsoft word from tayyab riaz Kamran Zafar
 

More from Kamran Zafar (12)

DFA Assignment solution.pptx
DFA Assignment solution.pptxDFA Assignment solution.pptx
DFA Assignment solution.pptx
 
TOA_WEEK 14.pptx
TOA_WEEK 14.pptxTOA_WEEK 14.pptx
TOA_WEEK 14.pptx
 
Drones in agri. by eskill india
Drones in agri. by eskill indiaDrones in agri. by eskill india
Drones in agri. by eskill india
 
exercise 3.3 solution /class 12th/ mathcity
exercise 3.3 solution /class 12th/ mathcityexercise 3.3 solution /class 12th/ mathcity
exercise 3.3 solution /class 12th/ mathcity
 
Lec 1 number systems converted
Lec 1 number systems convertedLec 1 number systems converted
Lec 1 number systems converted
 
Lecture 5 binary_codes
Lecture 5 binary_codesLecture 5 binary_codes
Lecture 5 binary_codes
 
Lecture java continued 1
Lecture java continued 1Lecture java continued 1
Lecture java continued 1
 
Lecture java continued
Lecture java continuedLecture java continued
Lecture java continued
 
Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)
 
digital systems and information
digital systems and informationdigital systems and information
digital systems and information
 
02 computing magazine september 2012
02 computing magazine september 201202 computing magazine september 2012
02 computing magazine september 2012
 
Learn microsoft word from tayyab riaz
Learn microsoft word from tayyab riaz  Learn microsoft word from tayyab riaz
Learn microsoft word from tayyab riaz
 

Recently uploaded

ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기Chiwon Song
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Neo4j
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Projectwajrcs
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilVICTOR MAESTRE RAMIREZ
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntelliSource Technologies
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9Jürgen Gutsch
 

Recently uploaded (20)

ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기
 
Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-Council
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptx
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9
 

Binary search tree operations

  • 2. DEFINATION OF BINARY SEARCH TREE Binary Search Tree is a node-based binary tree data structure which has the following properties. •The left subtree of a node contains only nodes with key lesser than the node's key. •The right subtree of a node contains only node with keys greater than the node's key.
  • 5. ADVANTAGES OF BST •#1)Searching Is Very Efficient We have all the nodes of BST in a specific order, hence searching for a particular item is very efficient and faster. This is because we need not search the entire and compare all nodes. We just have to compare the root node to the item which we are searching and then we decide whether we need to search in the left or right subtree.
  • 6. ADVANTAGES OF BST •#2) Efficient Working When Compared To Array And Linked Lists When we search an item in case of BST, we get rid of half of the left or right subtree at every step thereby improving the performance of search operation. This is in contrast to array or linked list in which we need to compare all the items sequentially to search a particular.
  • 7. ADVANTAGES OF BST •#3)Insert And Delete Are Faster Insert and delete operations also are faster when compared to other data structures like Linked Lists and Array.
  • 8. APPLICTION OF BST • BST is used to implement multilevel indexing in database application. • BST is also used to implement constructs like a dictionary. • BST can be used to implement various efficient searching algorithms. • BST is also used in applications that require a sorted list as input like the online stories. • BSTs are also used to evaluate expression using expression trees.
  • 9. CONCLUTION Binary search trees(BST) are a variation of the binary tree and are widely used in the software field. They are also called ordered binary trees as each node in BST is placed according to a specific order. Inorder traversal of BST gives us the sorted sequence of items in ascending order. When BSTs are used for searching, it is very efficient and is done within no time. BSTs are also used for a variety of application like Huffman's coding, Multilevel index in database ,etc.
  • 11. SEARCH OPERATION The Algorithm depends on the property of BST that if each left subtree has value below root and each right subtree has value above the root. If the value is below the root, we can say for sure that the value is not in the right subtree; we need to only search in the left subtree and if the value above root, we can say for sure that value is not in the left subtree; we need to only search in the right subtree.
  • 16. INSERT OPERATION Inserting a value in the correct position is similar to searching because we try to maintain the rule that the left subtree is lesser than root and the right subtree is larger than root. We keep going to either right subtree depending on the value and when we reach a point left or right subtree is null, we put the new code there.
  • 21. DELETE OPERATION There are three cases for deleting a node from a binary search tree.
  • 22. CASE-1 In the first case, the node to be delete is the leaf node. In such a case, simply delete the node from the tree.
  • 23. CASE-2 In the second case, the node to be deleted lies has a single child node. In such cases follow the step below 1.Replace that node with its child node. 2.Remove the child node from its original position.
  • 25. CASE-3 • In the third case, the node to be deleted has two children. In such a case follow the steps below: 1.Get the inorder successor of that. 2.Replace the node with the inorder successor. 3.Remove the inorder successor from its original position.
  • 28. PRESENTED BY: •Ehsan ul khaliq (F20-BsCS-5004) •Faisal Shehzad (F20-BsCS-5030) •Kamran Zafar (F20-BsCS-5039)