Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...