Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
665 views
in Technique[技术] by (71.8m points)

data structures - How to delete a node with 2 children nodes in a binary search tree?

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?

How to delete the node '5' from the this image and what might be the outcome?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...