SlideShare uma empresa Scribd logo
1 de 9
Binary Search Tree in Data
Structures
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
Introduction
 A binary search tree is a useful data structure for fast
addition and removal of data.
 It is composed of nodes, which stores data and also
links to upto two other child nodes.
 It is the relationship between the leaves linked to and
the linking leaf, also known as the parent node, which
makes the binary tree such an efficient data structure.
Cont…
 For a binary tree to be a binary search tree, the data of
all the nodes in the left sub-tree of the root node
should be less than the data of the root.
 The data of all the nodes in the right subtree of the
root node should be greater than equal to the data of
the root.
 As a result, the leaves on the farthest left of the tree
have the lowest values, whereas the leaves on the right
of the tree have the greatest values.
Binary Search Tree
Insertion in a BST
 To insert data into a binary tree involves a function
searching for an unused node in the proper position in
the tree in which to insert the key value.

 The insert function is generally a recursive function
that continues moving down the levels of a binary tree
until there is an unused leaf in a position which
follows the following rules of placing nodes.
Cont..
 Compare data of the root node and element to be
inserted.
 If the data of the root node is greater, and if a left
subtree exists, then repeat step 1 with root = root of
left subtree. Else,
 Insert element as left child of current root.
Cont..
 If the data of the root node is greater, and if a right
subtree exists, then repeat step 1 with root = root of
right subtree.
 Else, insert element as right child of current root.
BST Insertion
Assignment
 Explain Binary Search Tree in data structure with
suitable example and discuss basic operation.

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Selection sort
Selection sortSelection sort
Selection sort
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Multi ways trees
Multi ways treesMulti ways trees
Multi ways trees
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Selection sort
Selection sortSelection sort
Selection sort
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 

Semelhante a Binary search tree in data structures

Semelhante a Binary search tree in data structures (20)

binarysearchtreeindatastructures-200604055006 (1).pdf
binarysearchtreeindatastructures-200604055006 (1).pdfbinarysearchtreeindatastructures-200604055006 (1).pdf
binarysearchtreeindatastructures-200604055006 (1).pdf
 
Tree
TreeTree
Tree
 
nptel 2nd presentation.pptx
nptel 2nd presentation.pptxnptel 2nd presentation.pptx
nptel 2nd presentation.pptx
 
Unit iv data structure-converted
Unit  iv data structure-convertedUnit  iv data structure-converted
Unit iv data structure-converted
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Database Engine
Database EngineDatabase Engine
Database Engine
 
Biary search Tree.docx
Biary search Tree.docxBiary search Tree.docx
Biary search Tree.docx
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
Makalah if2091-2011-020
Makalah if2091-2011-020Makalah if2091-2011-020
Makalah if2091-2011-020
 
Tree
TreeTree
Tree
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 
binary search tree
binary search treebinary search tree
binary search tree
 
Binary tree
Binary treeBinary tree
Binary tree
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Trees
TreesTrees
Trees
 
104333 sri vidhya eng notes
104333 sri vidhya eng notes104333 sri vidhya eng notes
104333 sri vidhya eng notes
 
DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptx
 
Circular Linked List.pptx
Circular Linked List.pptxCircular Linked List.pptx
Circular Linked List.pptx
 

Mais de chauhankapil

Gray level transformation
Gray level transformationGray level transformation
Gray level transformationchauhankapil
 
Elements of visual perception
Elements of visual perceptionElements of visual perception
Elements of visual perceptionchauhankapil
 
JSP Client Request
JSP Client RequestJSP Client Request
JSP Client Requestchauhankapil
 
Jsp server response
Jsp   server responseJsp   server response
Jsp server responsechauhankapil
 
Markov decision process
Markov decision processMarkov decision process
Markov decision processchauhankapil
 
RNN basics in deep learning
RNN basics in deep learningRNN basics in deep learning
RNN basics in deep learningchauhankapil
 
Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)chauhankapil
 
Bayesian probabilistic interference
Bayesian probabilistic interferenceBayesian probabilistic interference
Bayesian probabilistic interferencechauhankapil
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javachauhankapil
 
Knowledge acquistion
Knowledge acquistionKnowledge acquistion
Knowledge acquistionchauhankapil
 
Knowledge based system
Knowledge based systemKnowledge based system
Knowledge based systemchauhankapil
 
Introduction of predicate logics
Introduction of predicate  logicsIntroduction of predicate  logics
Introduction of predicate logicschauhankapil
 
Types of inheritance in java
Types of inheritance in javaTypes of inheritance in java
Types of inheritance in javachauhankapil
 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicschauhankapil
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javachauhankapil
 
Propositional logic
Propositional logicPropositional logic
Propositional logicchauhankapil
 
Constructors in java
Constructors in javaConstructors in java
Constructors in javachauhankapil
 
Circular linked list
Circular linked listCircular linked list
Circular linked listchauhankapil
 

Mais de chauhankapil (20)

Gray level transformation
Gray level transformationGray level transformation
Gray level transformation
 
Elements of visual perception
Elements of visual perceptionElements of visual perception
Elements of visual perception
 
JSP Client Request
JSP Client RequestJSP Client Request
JSP Client Request
 
Jsp server response
Jsp   server responseJsp   server response
Jsp server response
 
Markov decision process
Markov decision processMarkov decision process
Markov decision process
 
RNN basics in deep learning
RNN basics in deep learningRNN basics in deep learning
RNN basics in deep learning
 
Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)
 
Bayesian probabilistic interference
Bayesian probabilistic interferenceBayesian probabilistic interference
Bayesian probabilistic interference
 
Jsp
JspJsp
Jsp
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Knowledge acquistion
Knowledge acquistionKnowledge acquistion
Knowledge acquistion
 
Knowledge based system
Knowledge based systemKnowledge based system
Knowledge based system
 
Introduction of predicate logics
Introduction of predicate  logicsIntroduction of predicate  logics
Introduction of predicate logics
 
Types of inheritance in java
Types of inheritance in javaTypes of inheritance in java
Types of inheritance in java
 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logics
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
 
Methods in java
Methods in javaMethods in java
Methods in java
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 

Último

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stageAbc194748
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 

Último (20)

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 

Binary search tree in data structures

  • 1. Binary Search Tree in Data Structures Prof. Neeraj Bhargava Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer
  • 2. Introduction  A binary search tree is a useful data structure for fast addition and removal of data.  It is composed of nodes, which stores data and also links to upto two other child nodes.  It is the relationship between the leaves linked to and the linking leaf, also known as the parent node, which makes the binary tree such an efficient data structure.
  • 3. Cont…  For a binary tree to be a binary search tree, the data of all the nodes in the left sub-tree of the root node should be less than the data of the root.  The data of all the nodes in the right subtree of the root node should be greater than equal to the data of the root.  As a result, the leaves on the farthest left of the tree have the lowest values, whereas the leaves on the right of the tree have the greatest values.
  • 5. Insertion in a BST  To insert data into a binary tree involves a function searching for an unused node in the proper position in the tree in which to insert the key value.   The insert function is generally a recursive function that continues moving down the levels of a binary tree until there is an unused leaf in a position which follows the following rules of placing nodes.
  • 6. Cont..  Compare data of the root node and element to be inserted.  If the data of the root node is greater, and if a left subtree exists, then repeat step 1 with root = root of left subtree. Else,  Insert element as left child of current root.
  • 7. Cont..  If the data of the root node is greater, and if a right subtree exists, then repeat step 1 with root = root of right subtree.  Else, insert element as right child of current root.
  • 9. Assignment  Explain Binary Search Tree in data structure with suitable example and discuss basic operation.