Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views3 pages

Experiment 4

The document outlines an experiment focused on implementing and analyzing operations on a Binary Search Tree (BST), including insertion, deletion, searching, and displaying elements. It provides algorithms for each operation and emphasizes the efficiency and utility of BSTs in maintaining sorted order and dynamic updates. The conclusion highlights the relevance of BSTs in various applications such as databases and file systems.

Uploaded by

Aqsa Khan
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
16 views3 pages

Experiment 4

The document outlines an experiment focused on implementing and analyzing operations on a Binary Search Tree (BST), including insertion, deletion, searching, and displaying elements. It provides algorithms for each operation and emphasizes the efficiency and utility of BSTs in maintaining sorted order and dynamic updates. The conclusion highlights the relevance of BSTs in various applications such as databases and file systems.

Uploaded by

Aqsa Khan
Copyright
© © All Rights Reserved
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/ 3

Experiment No.

4
Name of Experiment: Binary Search Tree and Operations
Aim: Implement Insert, Delete, Search and Display operations on Binary Search Tree and
analyze space and time complexity
Software Required: C/C++, Java Compiler
Pre-Requisites: C Programming Concepts, Data Structures
Theory:
A Binary Search Tree (BST) is a node-based binary tree where:
●​ The left child of a node contains only nodes with keys less than the node’s key.
●​ The right child contains only nodes with keys greater than the node’s key.
●​ BST allows efficient insertion, searching, and deletion.
Common Operations:
●​ Insertion: Adds a node while maintaining the BST property.
●​ Search: Locates a node with a given value.
●​ Deletion: Removes a node with proper restructuring.
●​ Display: Shows tree contents (typically via In-order traversal)
Algorithm:
1. Insert Operation:
INSERT(root, key):
if root is NULL:
return new node with key
if key < root.data:
root.left = INSERT(root.left, key)
else if key > root.data:
root.right = INSERT(root.right, key)
return root
2. Search Operation:
SEARCH(root, key):
if root is NULL or root.data == key:
return root
if key < root.data:
return SEARCH(root.left, key)
else:
return SEARCH(root.right, key)
3. Delete Operation:
DELETE(root, key):
if root is NULL:
return root
if key < root.data:
root.left = DELETE(root.left, key)
else if key > root.data:
root.right = DELETE(root.right, key)
else:
// Node with only one child or no child
if root.left is NULL:
return root.right
else if root.right is NULL:
return root.left

// Node with two children


temp = MINVALUE(root.right)
root.data = temp.data
root.right = DELETE(root.right, temp.data)
return root

MINVALUE(node):
current = node
while current.left is not NULL:
current = current.left
return current
4. Display Operation (In-order Traversal):
INORDER(root):
if root is not NULL:
INORDER(root.left)
print(root.data)
INORDER(root.right)

Conclusion:
The Binary Search Tree (BST) is a fundamental data structure that supports efficient searching,
insertion, and deletion operations. With proper implementation, a BST maintains sorted order
and allows dynamic updates. Traversals like in-order can be used to display elements in sorted
order, making BSTs highly useful in many applications like databases, file systems, and more.

You might also like