码迷,mamicode.com
首页 > 其他好文 > 详细

How to delete a node in BST?

时间:2016-04-21 18:34:53      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

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.

How to delete a node in BST?

标签:

原文地址:http://www.cnblogs.com/dingjunnan/p/5417784.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!