Archive for category Simple Ones!!

How to delete minimum node from a Binary Search Tree?


This is going to be simple.  As you already know that the data in Binary Search Tree is already organized, you know exactly where to find the node with minimum value. If you start from the root and keep going to left till you can traverse the tree, the last node is going to be the minimum one. Here is the C++ code for that. I am trying to put the codes in proper indentation, but its not working for me with the blog.

struct tnode *delmin(struct tnode *p){
struct tnode *temp=p;
while( temp->left->left != NULL){
temp = temp->left;
}
temp->left=NULL;
delete(temp->left);
return p;
}

Now try to write the code for deleting the maximum one. Isn’t it quite simple and obvious?

Advertisements

Leave a comment