The document outlines operations for managing a Binary Search Tree (BST), focusing on deletion, insertion, and search operations. It details three cases for deletion: removing a leaf node, deleting a node with one child, and replacing a node with its inorder successor when it has two children. Additionally, it explains how to insert new keys and provides an example of constructing a BST from a sequence of numbers.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views14 pages
Deletion Operation
The document outlines operations for managing a Binary Search Tree (BST), focusing on deletion, insertion, and search operations. It details three cases for deletion: removing a leaf node, deleting a node with one child, and replacing a node with its inorder successor when it has two children. Additionally, it explains how to insert new keys and provides an example of constructing a BST from a sequence of numbers.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14
Deletion Operation
• Deletion Operation is performed to delete a
particular element from the Binary Search Tree. • When it comes to deleting a node from the binary search tree, three cases are possible. Case-01: Deletion Of A Node Having No Child (Leaf Node) • Just remove / disconnect the leaf node that is to deleted from the tree. Case-02: Deletion Of A Node Having Only One Child • Consider the following example where node with value = 30 is deleted from the BST. Case-03: Deletion Of A Node Having Two Children • Consider the following example where node with value = 15 is deleted from the BST • Method-1: – Visit to the right subtree of the deleting node. – Pluck the least value element called as inorder successor. – Replace the deleting element with its inorder successor. Insertion operation • The insertion of a new key always takes place as the child of some leaf node. • For finding out the suitable leaf node, – Search the key to be inserted from the root node till some leaf node is reached. – Once a leaf node is reached, insert the key as child of that leaf node. BST Operations • Commonly performed binary search tree operations are: BST Operations
Search Operation • Search Operation is performed to search a particular element in the Binary Search Tree. • For searching a given key in the BST, – Compare the key with the value of root node. – If the key is present at the root node, then return the root node. – If the key is greater than the root node value, then recur for the root node’s right subtree. – If the key is smaller than the root node value, then recur for the root node’s left subtree. Example • Construct a Binary Search Tree (BST) for the following sequence of numbers: 50, 70, 60, 20, 90, 10, 40, 100 • When elements are given in a sequence, – Always consider the first element as the root node. – Consider the given elements and insert them in the BST one by one. Binary Search Tree construction • In a binary search tree (BST), each node contains: – Only smaller values in its left sub tree – Only larger values in its right sub tree