How to delete a node in BST?

Step 1:

Use the key to find this node in BST, time complexity is log(n)

Step 2:

after finding this node, we have 3 different conditions:

1, if this node's left and right children are null, just set this node's parent's link to this to null;

2, if this node only has one child, just replace this node with it's child;

3, if this node has two children, then we need to find the minimum key node in this node's right subtree, then replace this node with the minimum key node, then delete this minimum key node in the right subtree.

posted on 2016-04-21 17:15  dingjunnan  阅读(110)  评论(0编辑  收藏  举报

导航