You are on page 1of 2

Benha University Electrical Engineering Department

Benha Faculty of Engineering Data Structures and Algorithms


(E1324)

lab (4) Binary Search Tree BST

LIST OF EXPERIMENTS
1. Implementation of Binary Search Tree and its basic operations.

Objectives:
1) Understand the data structure BST and its basic operations.
2) Understand the method of constructing the BST ADT and defining its
operations.

To write a C++ program to create a binary search tree and perform various operations
like insertion, deletion, find an element, find minimum element, maximum element and
display the tree on it. And write an algorithm and corresponding program for depth first
search and breadth first search.
INTRODUCTION
A binary search tree (BST) is a tree in which all nodes follows the below mentioned
properties
The left sub-tree of a node has key less than or equal to its parent node's key.
The right sub-tree of a node has key greater than or equal to its parent node' s key.
Thus, a binary search tree (BST) divides all its sub-trees into two segments;
left sub-tree and right sub-tree and can be defined as
left_subtree (keys) ≤ node (key) ≤ right_subtree (keys).

Following are basic primary operations of a tree which are following.


Search − search an element in a tree.
Insert − insert an element in a tree.
Delete – delete an element from a tree.
Find max and min value
Preorder Traversal − traverse a tree in a preorder manner.
Inorder Traversal − traverse a tree in an inorder manner.
Postorder Traversal − traverse a tree in a postorder manner.
BFS Traversal – traverse a tree in a level order manner.

Binary Search Tree can be implemented as a linked data structure in which each node
is an object with two pointer fields and a data field. The two pointer fields left and right
point to the nodes corresponding to the left child and the right child respectively. NIL
in any pointer field signifies that there exists no corresponding child.
Algorithm:

Step 1: Start.
Step 2: Create a Binary Search Tree for N elements.
Step 3: Traverse the tree in inorder.
Step 4: Traverse the tree in preorder
Step 5: Traverse the tree in postorder.
Step 6: Traverse the tree in level order
Step 7: Search the given key element in the BST.
Step 8: Delete an element from BST.
Step 9: Insert new element in BST
Step 10: Find the max and min element in BST
Step 11: Stop

Program: To be written by the student using the above algorithm.


Observations: To be written by student after implementing the algorithm.
1)Input:
2)Output:

H.W
Design, Develop and Implement a menu driven Program in C++ for the following
operations on Binary Search Tree (BST) of Integers
a. Create a BST of N Integers: 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2
b. Traverse the BST in Inorder, Preorder and Post Order
c. Search the BST for a given element (KEY) and report the appropriate message
d. Delete an element (ELEM) from BST.
e. Exit.

You might also like