0% found this document useful (0 votes)
13 views14 pages

Binary Search Tree Presentation

Uploaded by

shruti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

Binary Search Tree Presentation

Uploaded by

shruti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Binary Search

Tree
• Binary Search tree can be defined as a class of binary trees, in
which the nodes are arranged in a specific order.

• This is also called ordered binary tree.

• In a binary search tree, the value of all the nodes in the left sub-
tree is less than the value of the root.

• Similarly, value of all the nodes in the right sub-tree is greater


than to the value of the root.

• This rule will be recursively applied to all the left and right sub-
trees of the root.
Insertion in Binary Search Tree

(BST)
A new key is always inserted at the leaf by maintaining the property
of the binary search tree.
• We start searching for a key from the root until we hit a leaf node.
• Once a leaf node is found, the new node is added as a child of the
leaf node.
Q. Create the binary search tree using the following data elements.
43, 10, 79, 90, 12, 54, 11, 9, 50

1.Insert 43 into the tree as the root of the tree.


2.Read the next element, if it is lesser than the root node element,
insert it as the root of the left sub-tree.
3.Otherwise, insert it as the root of the right of the right sub-tree.
Construct BST for
23,56,78,52,96,28,12,2,5
Deletion in Binary Search Tree
(BST)
Given a BST, the task is to delete a node in this BST, which can be broken
down into 3 scenarios:
2. The node to be deleted has only one child:
In this case, replace the node with its child and delete the child
node.
3. The node to be deleted has two children:
It is a bit complex case compare to other two cases.
However, the node which is to be deleted, is replaced
with its in-order successor or predecessor recursively
until the node value (to be deleted) is placed on the leaf
of the tree. After the procedure, replace the node with
NULL

You might also like