Binary Search Tree(BNS)
BNS is also known as versions of sorted version of binary tree
for the node of the left subtree is contain smaller number than those store in x
for the node of the right subtree is contain greater number than those store in x
there are three operation in BNS:
- insert()
- search()
- remove()
The insert of BNS is to store is done recursively.
let the new node's key be X, then we have a number of 30 of the beginning of the first node.
if the node key input is smaller it will move the node to the left subtree side, if the node key is greater than it will move to the right subtree side.
here is the example:-
Now we will discuss search of BNS or can be call find of BNS. The search is pretty easy it just finds the node key of the X in the tree. if the search found the node it search then it will print the "the node key is found in the tree". The search algorithm is pretty much similar to insert but it job not to insert but to find only.
Lastly, remove BNS which is to remove the node of the tree. just as previous picture if I want to remove the node 35 the 32 will be taking over it.
here the example :
Comments
Post a Comment