Delete operation on binary search tree

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 22K views
Messages
2,590
Reaction score
4
The following diagram is from the section in my notes titled "Operations on Binary Search Trees". Specifically it explains via pseudocode how to implement a delete function for a BST:

http://img410.imageshack.us/img410/4225/deletetreexz0.jpg

What I don't understand in the 2nd box is why "return T.left" is written. I thought the purpose of deleting a tree node in a BST would be to literally delete the object corresponding to the tree node. Instead the pseudocode appears to return the child node of the node to be deleted. Why is this done?
 
Last edited by a moderator:
Physics news on Phys.org
This is not a delete function, and it doesn't include the case where an element has two children. It appears to be a sub-function that should be called by another function that isn't described.
 
Last edited:
Thanks for replying, Jeff. I did a search on Google and found the following:
http://www.cs.mcgill.ca/~cs251/OldCourses/1997/topic9/

It turns out that deleting a BST node entails removing only that node itself and not its child sub-trees as I had thought it would. The child sub-trees of that node-to-be deleted would then be re-allocated in the BST. I've uploaded the portion of my notes which describe this operation in full. But it's strange that there isn't any delete keyword which I had expected, nor is there any pseudo-code which explains that deleting a node would require "re-pointing" the pointers of the parent tree-node of the node-to-be-deleted.
 

Attachments

Last edited by a moderator: