Search Node From Binary Search Tree


In order to searching a node in binary search tree we have to follows the step given below:
Step 1: First we have to check weather binary search tree is empty or not. If binary search tree is empty then search is unsuccessful.
Step 2: If binary search tree is not empty then we compare the value of a node to be searched with root node of binary search tree. If both values are equal then search is successful otherwise we have two possibilities.
(A) If value of the node to be searched is less than the value of root node then we have to search node in left sub tree of root node.
(B) If value of the node to be searched is greater than the value of root node then we have to search node in right sub tree of root node.
Step 2 is repeated recursively until node to be searched is found or all the nodes in a binary search tree are compared with the node to be searched.

     

Algorithm to Search Node in Binary Search Tree


Step 1: If ROOT = NULL then
            Write “Tree is Empty. Search Un Successful”
Step 2: If X=ROOT->INFO then
            Write “Search is Successful”            
             Return (ROOT)
Step 3: If X < ROOT->INFO then
            Call SEARCH (ROOT->LPTR, X)
            Else
            Call SEARCH (ROOT->RPTR, X)

Download Projects


Download Programs