SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
Binary Search Tree In Python
SlideMake.com
1
Introduction to Binary Search Tree
• A binary search tree is a data structure that organizes data in a
hierarchical manner.
• It is a type of binary tree where each node has at most two children.
• The left child of a node contains a value smaller than the parent,
while the right child contains a value greater than the parent.
2
Operations on Binary Search Tree
• Insertion: To add a new node to the tree, we compare the value with
the current node and follow the left or right child accordingly until we
find an empty spot.
• Deletion: When deleting a node, we need to consider three cases:
• - If the node has no children, we can simply remove it.
• - If the node has one child, we replace it with its child.
• - If the node has two children, we find the next smallest value (or
next largest) in the tree and replace it with the node to be deleted.
• Your third bullet
3
Traversing a Binary Search Tree
• Inorder Traversal: In this traversal, we visit the left subtree, then the
root, and finally the right subtree. This results in a sorted list of
values.
• Preorder Traversal: In this traversal, we visit the root, then the left
subtree, and finally the right subtree.
• Postorder Traversal: In this traversal, we visit the left subtree, then
the right subtree, and finally the root.
4
Searching in a Binary Search Tree
• To search for a value in a binary search tree, we compare the value
with the current node.
• If the value matches, we have found the node.
• If the value is smaller, we move to the left child.
5
Advantages of Binary Search Tree
• Efficient searching: Due to the hierarchical structure of the tree,
search operations can be performed quickly by eliminating half of
the remaining nodes at each step.
• Sorted storage: Inorder traversal of a binary search tree gives the
elements in sorted order, which can be useful in certain scenarios.
• Insertion and deletion flexibility: Binary search trees allow dynamic
insertion and deletion of nodes, maintaining the tree's balance
through rotation operations.
6
Disadvantages of Binary Search Tree
• Imbalanced trees: If the elements are inserted in a specific order, the
tree can become unbalanced, resulting in poor performance for
search operations.
• Lack of uniqueness: Binary search trees do not inherently enforce
uniqueness of values, which means duplicate values can be
inserted.
• Memory overhead: Binary search trees require additional memory to
store the tree structure, including pointers to left and right children.
7
Conclusion
• Binary search trees are a versatile data structure for organizing and
accessing data efficiently.
• They offer advantages such as efficient searching, sorted storage,
and flexibility in insertion and deletion.
• However, they can suffer from imbalanced trees, lack of uniqueness,
and memory overhead. Careful consideration of the data and
appropriate balancing techniques can help mitigate these issues.

More Related Content

PPTX
types of trees1234567890qwertyuiopasdfg.pptx
PPTX
Database Engine
PPTX
unit-2-data structure and algorithms-tree-2024-1.pptx
PPTX
SEARCHING AND SORTING ALGORITHMS, TYPES OF SORTING
PPTX
Binary Search Tree
PDF
unit-2-dsa-tree introduction of tree and terninology
PPTX
07-Lecture.pptxlkjslkjdfkjskljdflksj;fdkj
PPTX
learn tree, linked list, queue, stack, and other algo
types of trees1234567890qwertyuiopasdfg.pptx
Database Engine
unit-2-data structure and algorithms-tree-2024-1.pptx
SEARCHING AND SORTING ALGORITHMS, TYPES OF SORTING
Binary Search Tree
unit-2-dsa-tree introduction of tree and terninology
07-Lecture.pptxlkjslkjdfkjskljdflksj;fdkj
learn tree, linked list, queue, stack, and other algo

Similar to Binary Search Tree In Python.pptx (20)

PDF
B Tree, Introduction ,example,Splay tree
PPTX
Binary tree
PPT
Binary trees
PPTX
Saikat techhnology of techtechhnology of techGhorai.pptx
PPTX
01-B-Tree in data structures and algorithms
PPTX
Search tree,Tree and binary tree and heap tree
PPTX
Searching, Sorting and Hashing Techniques
PPTX
Data structfghz€zdsrgnhlhlfdshllures.pptx
PPTX
Group 5-DSA.pptx........................
PPT
Tree
PPTX
Data structure(Part 2)
PPTX
4. Apply data structures such as arrays, linked lists, and trees as an abstra...
PPTX
Tree data structure.pptx
PDF
Binary search
PPTX
Pratechhnology of techtik Gautechhnology of techrav.pptx
PPTX
Advanced Trees
PPTX
Rahat & juhith
PDF
unit-2-dsa-tree-2024-1 (1) (1).pdf data structure
PPTX
nptel 2nd presentation.pptx
PPTX
Presentation1-Data structure S-Tree.pptx
B Tree, Introduction ,example,Splay tree
Binary tree
Binary trees
Saikat techhnology of techtechhnology of techGhorai.pptx
01-B-Tree in data structures and algorithms
Search tree,Tree and binary tree and heap tree
Searching, Sorting and Hashing Techniques
Data structfghz€zdsrgnhlhlfdshllures.pptx
Group 5-DSA.pptx........................
Tree
Data structure(Part 2)
4. Apply data structures such as arrays, linked lists, and trees as an abstra...
Tree data structure.pptx
Binary search
Pratechhnology of techtik Gautechhnology of techrav.pptx
Advanced Trees
Rahat & juhith
unit-2-dsa-tree-2024-1 (1) (1).pdf data structure
nptel 2nd presentation.pptx
Presentation1-Data structure S-Tree.pptx
Ad

More from RohanThota3 (6)

PPTX
Aluminium and its alloy study about aluminium
PDF
readerwriter-190410082551.pdf
PPTX
Arithmetic operators
PPTX
22R01A66C1.pptx
PPTX
22R01A67C1.pptx
PPTX
M.pranavi[22R01A6735] maths^.pptx
Aluminium and its alloy study about aluminium
readerwriter-190410082551.pdf
Arithmetic operators
22R01A66C1.pptx
22R01A67C1.pptx
M.pranavi[22R01A6735] maths^.pptx
Ad

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Lesson notes of climatology university.
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
Final Presentation General Medicine 03-08-2024.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Complications of Minimal Access Surgery at WLH
STATICS OF THE RIGID BODIES Hibbelers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
TR - Agricultural Crops Production NC III.pdf
Pre independence Education in Inndia.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
01-Introduction-to-Information-Management.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Basic Mud Logging Guide for educational purpose
Lesson notes of climatology university.
Microbial disease of the cardiovascular and lymphatic systems
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
O5-L3 Freight Transport Ops (International) V1.pdf

Binary Search Tree In Python.pptx

  • 1. Binary Search Tree In Python SlideMake.com
  • 2. 1 Introduction to Binary Search Tree • A binary search tree is a data structure that organizes data in a hierarchical manner. • It is a type of binary tree where each node has at most two children. • The left child of a node contains a value smaller than the parent, while the right child contains a value greater than the parent.
  • 3. 2 Operations on Binary Search Tree • Insertion: To add a new node to the tree, we compare the value with the current node and follow the left or right child accordingly until we find an empty spot. • Deletion: When deleting a node, we need to consider three cases: • - If the node has no children, we can simply remove it. • - If the node has one child, we replace it with its child. • - If the node has two children, we find the next smallest value (or next largest) in the tree and replace it with the node to be deleted. • Your third bullet
  • 4. 3 Traversing a Binary Search Tree • Inorder Traversal: In this traversal, we visit the left subtree, then the root, and finally the right subtree. This results in a sorted list of values. • Preorder Traversal: In this traversal, we visit the root, then the left subtree, and finally the right subtree. • Postorder Traversal: In this traversal, we visit the left subtree, then the right subtree, and finally the root.
  • 5. 4 Searching in a Binary Search Tree • To search for a value in a binary search tree, we compare the value with the current node. • If the value matches, we have found the node. • If the value is smaller, we move to the left child.
  • 6. 5 Advantages of Binary Search Tree • Efficient searching: Due to the hierarchical structure of the tree, search operations can be performed quickly by eliminating half of the remaining nodes at each step. • Sorted storage: Inorder traversal of a binary search tree gives the elements in sorted order, which can be useful in certain scenarios. • Insertion and deletion flexibility: Binary search trees allow dynamic insertion and deletion of nodes, maintaining the tree's balance through rotation operations.
  • 7. 6 Disadvantages of Binary Search Tree • Imbalanced trees: If the elements are inserted in a specific order, the tree can become unbalanced, resulting in poor performance for search operations. • Lack of uniqueness: Binary search trees do not inherently enforce uniqueness of values, which means duplicate values can be inserted. • Memory overhead: Binary search trees require additional memory to store the tree structure, including pointers to left and right children.
  • 8. 7 Conclusion • Binary search trees are a versatile data structure for organizing and accessing data efficiently. • They offer advantages such as efficient searching, sorted storage, and flexibility in insertion and deletion. • However, they can suffer from imbalanced trees, lack of uniqueness, and memory overhead. Careful consideration of the data and appropriate balancing techniques can help mitigate these issues.