Delete operation on binary search tree

Click For Summary
SUMMARY

The discussion centers on the implementation of a delete operation for a Binary Search Tree (BST) as outlined in pseudocode. The key point of confusion is the line "return T.left," which indicates that the function does not delete the node directly but instead returns the child node of the node to be deleted. This approach is necessary because deleting a node in a BST involves re-linking the child sub-trees rather than removing them entirely. The discussion highlights that a complete delete function must also handle cases where the node has two children, which is not covered in the provided pseudocode.

PREREQUISITES
  • Understanding of Binary Search Tree (BST) structure
  • Familiarity with pseudocode and algorithm design
  • Knowledge of pointer manipulation in data structures
  • Basic concepts of tree traversal methods
NEXT STEPS
  • Study the complete delete operation for Binary Search Trees, including cases with two children
  • Learn about pointer re-linking techniques in tree data structures
  • Explore the implementation of tree traversal algorithms to assist in node deletion
  • Review additional resources on BST operations, such as those from academic institutions
USEFUL FOR

Computer science students, software developers, and anyone interested in data structure manipulation and algorithm optimization will benefit from this discussion.

Defennder
Homework Helper
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:
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:

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 13 ·
Replies
13
Views
5K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
75K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
7K