Btsearch (Bt, k)
The above Function searches the desired element from a given binary tree, and returns ‘true’ if matches. The pointer variable ‘Bt’ holds the address of the root node. Variable ‘k’ holds the key-value of the element to be searched. The Function works in a recursive manner. The structure of a node is same as described earlier.
Step 1 Is Empty ?
if (BtEmpty (Bt)) then
message : “Empty tree”
Step 2 Root node is the node to be searched
if (data (Bt) = k) then
Step 3 If key value is less than root
if (k < data (Bt)) then
return (Btsearch (Lchild (Bt), k))
Step 4 If key value is greater than root.
if (k > data (Bt)) then
return (Btsearch (Rchild (Bt), K))