Home » Data Structure & Algorithms » insert,search,delete and traversal operation in BST

insert,search,delete and traversal operation in BST

Question :

WAP to show insert,search,delete and traversal operation in BST

 

 

Algorithm :

The problem is solved in recursive way.

Hint : Inorder(left->root->right)  traversal of BST gives a ascending sorted array..

Step 1 : If the node is null ,then return false.

Step 2 : Initialize a temp variable to Integer.MIN_VALUE (i.e. -2147483648)

Step 3 : Do a Inorder traversal of tree by travesring left subtree,root and right subtree in order.

Step 4 : While doing Inorder traversal check if the current node’s value  is less than temp.If the current node value is less than temp then it is not binary search tree else assign temp to current node’s value and keep on doing Inorder traversal.

 
 


Leave a comment

Your email address will not be published. Required fields are marked *

18 − ten =