首页 > 其他 > 详细

How to delete a node in BST?

时间:2016-04-21 18:32:59      阅读:212      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!