如何在二叉搜索树中删除带有2个子节点的节点? [英] How to delete a node with 2 children nodes in a binary search tree?

查看:550
本文介绍了如何在二叉搜索树中删除带有2个子节点的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在二叉树中删除带有2个子节点的节点?

How to delete a node with 2 children nodes in a binary tree?

有什么方法可以删除它吗?我上了谷歌但没有明确的想法。任何人用图解表示来解释它?

Is there any kind of method to remove it? I googled it. But didn't get clear idea about it. Anybody explain it with diagrammatic representation?

如何从该图像中删除节点'5'以及可能的结果?

推荐答案

所述节点左侧最左侧的孩子,右侧最右侧的小孩左侧。然后,您从底部删除它被替换的孩子。

you replace said node with the left most child on its right side, or the right most child on its left side. You then delete the child from the bottom that it was replaced with.

删除五个可能会产生一个树,其中3为根,或18为根,具体取决于哪个

Deleting five could yield either a tree with 3 as its root or 18 as its root, depending on which direction you take.

看起来你从这个网站获得了这个图像: http://www.algolist.net/Data_structures/Binary_search_tree/Removal

It looks like you got that image from this site: http://www.algolist.net/Data_structures/Binary_search_tree/Removal

它显示了您想要的图像的算法。

It shows the algorithm you want with images too.

这篇关于如何在二叉搜索树中删除带有2个子节点的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆