SlideShare a Scribd company logo
Welcome
Binary Search treeInsertion, Search and Deletion operation and BST sort
Team Members
Israt Jahan Fateha (151-15-5036)
Md. Eyakub Sorkar (151-15-4674)
Mehedi Imam Shafi (151-15-5248)
Sajiya (151-15-5256)
Sanjida Tasnim (143-15-4397)
B S T
inary
earch ree
Condition for a binary tree to be a BST
Left child is smaller than parent
Right child is greater than parent
55
45 65
58 675335
Example of binary search tree
Basic Operations
• Insertion
• Search
• Deletion
• Traversal
• Sort
Insertion
 There are three rules before we go to the binary insertion search. The first rule is , A parent node
should not have more than two children. If it does, it is not binary search tree. The second rule is,
the value of parent is always greater than the right child. And the third rule is, the value of parent
is always smaller than the left child.
40
8010
Binary search tree insertion
Key is 6
inserted
10
-5 16
-8 7 18
6
Binary search tree insertion
Key is 17
inserted
10
-5 16
-8 7 18
6 17
Binary search tree insertion
Key is 19
inserted
10
15
16
18
19
Time complexity
How much time doe it take to insertion into binary search tree. The worst case, the time it takes
to insert into binary search tree is O(n). Its possible all the nodes have just one child and they are
linear like this one and the worst case here will be O(n).
10
15
16
18
19
Time complexity
If the tree is a balanced tree, the worst case to insert into such kind of tree is O(log(n)).
10
-5 16
-8 7 18
6 17
Search
What will we search?
How to search?
65
9
-4 5
4
5 is less than 6
go to the left child
5 is more than 4
go to the right child
Searched value has
been found
Algorithm:
Here k is the key that is searched for and x is the start
node.
BST-Search(x, k)
1. y ← x
2. while y ≠ nil do
3. if key[y] = k then return y
4. else if key[y] < k then y ← right[y]
5. else y ← left[y]
6. return (“NOT FOUND”)
CODE in C++:
bool BinarySearchTree::search( int value) {
if (root == NULL)
return false;
else
return root->search(value);
}
bool BSTNode::search( int value) {
if (value == this->value)
return true;
else if (value < this->value) {
if (left == NULL)
return false;
else
return left->search(value);
} else if (value > this->value) {
if (right == NULL)
return false;
else
return right->search(value);
}
return false;
}
Time Complexity of Searching in
Binary Search Tree
O( log(n) )O(n)
Deletion
Deleting a node has no child:
5
182
-4 3
5
18
2
3
Deleting a node with one child:
5
-4
2
25
18
21
19
3
5
-4
2
19
21
253
Deleting a node with two children:
5
9
12
19
213-4
2
21
5
9
19
213-4
2
2519
Sort
Already sorted during the step of insertion
TraversalPre-order In-order Post-order
In-order
55
45 65
58 675335
In-order traversal: 35 45 53 55 58 65 67
Pre-Order
55
45 65
58 675335
Pre-order traversal: 55 45 35 53 65 58 67
Post-Order
55
45 65
58 675335
Post-order: 35 53 45 58 67 65 55
Real Life Use of Binary Search Tree
10,000,0007log(10000000)
Maintaining a huge library
Game Objects
References:
1. http://en.wikipedia.org/binary=search-tree/
2. http://geeksourceforge.com/bst-basic
3. http://github.com/cpp@master/binary-tree/bst.cpp
4. https://www.quora.com/What-are-the-real-world-examples-of-binary-trees-not-search-tree
5. http://www.geeksforgeeks.org/618/
Thank You all
For being with us.

More Related Content

PPT
binary search tree
PDF
Binary Search Tree
PPT
Ch13 Binary Search Tree
PPT
Binary Search Tree and AVL
PPT
BINARY SEARCH TREE
PPT
Binary search tree(bst)
PPTX
Brain Computer Interface (BCI)
PPTX
Android application project presentation.
binary search tree
Binary Search Tree
Ch13 Binary Search Tree
Binary Search Tree and AVL
BINARY SEARCH TREE
Binary search tree(bst)
Brain Computer Interface (BCI)
Android application project presentation.

Recently uploaded (20)

PPTX
master seminar digital applications in india
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Classroom Observation Tools for Teachers
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Lesson notes of climatology university.
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Structure & Organelles in detailed.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
RMMM.pdf make it easy to upload and study
master seminar digital applications in india
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Classroom Observation Tools for Teachers
Microbial diseases, their pathogenesis and prophylaxis
O5-L3 Freight Transport Ops (International) V1.pdf
Lesson notes of climatology university.
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Structure & Organelles in detailed.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
STATICS OF THE RIGID BODIES Hibbelers.pdf
RMMM.pdf make it easy to upload and study
Ad
Ad

Binary Search Tree