WELCOME
TO
BINARY SEARCH TREE
(BST)
PRESENTATION
MEMBER
S
Kainat
Hafsa
Esha
Binary Search Tree (BST):
A binary search tree is a rooted binary tree
in which the nodes are arranged in strict
total order in which the nodes with keys
greater than any particular node is stored
on the right sub-trees and the ones with
equal to or less than are stored on the left
sub-tree satisfying the binary search
property.
Binary search tree is a data structure that quickly allows
us to maintain a sorted list of numbers.
It is called a binary tree because each tree node has a maximum of
two children.
It is called a search tree because it can be used to search for the
presence of a number in O(log(n)) time
Non-leaf nodes are also known as parent
nodes as they have more than 0 child and
less than two children.
A leaf procedure is one that doesn't all any
other procedures. A non-leaf procedure is
one that does call another procedure.
Insertion in a Binary Search Tree
Insertion is fairly simple if you understood
search perfectly.
Try to search the BST for the node to be inserted
As the node wouldn’t exist we will hit the leaf node,
with null as child node right!
Insert the new node here
Voila! Party, you’ve inserted
There may exist multiple valid ways for the insertion, as
long as the tree remains a BST after insertion.
Insert x at the last spot on the path traversed inser=5
The node to be deleted is a leaf node
It is the simplest case, in this case, replace the leaf node
with the NULL and simple free the allocated space.
In the following image, we are deleting the node 85,
since the node is a leaf node, therefore the node will be
replaced with NULL and allocated space will be freed.
The node to be deleted has only one child.
In this case, replace the node with its child and delete the child node,
which now contains the value which is to be deleted. Simply replace
it with the NULL and free the allocated space.
In the following image, the node 12 is to be deleted. It has only one
child. The node will be replaced with its child node and the replaced
node 12 (which is now leaf node) will simply be deleted.
In the following image, the node 50 is to be deleted which is
the root node of the tree. The in-order traversal of the tree
given below.
6, 25, 30, 50, 52, 60, 70, 75.
replace 50 with its in-order successor 52. Now, 50 will be moved to the leaf
of the tree, which will simply be deleted.
THANKYOU