Delete operation on binary search tree

AI Thread Summary
The discussion centers on the implementation of a delete function for a Binary Search Tree (BST) as outlined in pseudocode. A key point of confusion arises regarding the line "return T.left," which suggests that instead of deleting the node directly, the function returns the left child of the node to be deleted. This raises questions about the nature of the delete operation, as it seems to imply that the function does not fully handle the complexities of node deletion, particularly in cases where the node has two children. Further research reveals that deleting a BST node involves removing the node itself while reassigning its child sub-trees to maintain the tree's structure. The discussion highlights a lack of clarity in the pseudocode regarding the necessary pointer adjustments for the parent node, indicating that the provided pseudocode may be a simplified version of a more complex operation.
Defennder
Homework Helper
Messages
2,590
Reaction score
5
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:
Technology 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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top