Insertion Operations in binary search tree


1  

       Operations of binary search tree –



.           Search – searches an element in a tree.

Algorithm -
While data not found
If root==search_data
            Return root
Else
If search_data>node_data
            Go to right sub tree
If data found
            Return node
Else
            Return data not found
End while
End if

                        OR

·            Step 1: Read the search element from the user
·            Step 2: Compare, the search element with the value of root node in the tree.
·            Step 3: If both are matching, then display "Given node found!!!" and terminate the function
·            Step 4: If both are not matching, then check whether search element is smaller or larger than that node value.
·            Step 5: If search element is smaller, then continue the search process in left subtree.
·            Step 6: If search element is larger, then continue the search process in right subtree.
·            Step 7: Repeat the same until we found exact element or we completed with a leaf node
·            Step 8: If we reach to the node with search value, then display "Element is found" and terminate the function.
·            Step 9: If we reach to a leaf node and it is also not matching, then display "Element not found" and terminate the function.