简体   繁体   中英

Binary Search Tree - Deletion

Regarding the deletion operation and specifically the case where a node has exactly 2 subtrees I know that choosing to find the minimum element of the right subtree to 'substitute' the corresponding element is the way to go as the sorted property is preserved.

However why not choose the maximum element of the left subtree of the corresponding element?

I think that the sorted property does not break and can't think of a counter example.

From what I know, there's no "concrete" rule to always choose the minimum element of the right subtree. Judging by symmetry, using the maximum element from the left subtree would also work.

Logically speaking, the inorder traversal of a BST produces a sorted output. Consider the following output

....A B C....

Here, A and C are the inorder predecessor (basically, the maximum element from the left subtree of B ) and inorder successor (the minimum element from the right subtree of B ) respectively. Replacing B by either C or A will not change the sorted order, so there's no reason to say that C is the only option to replace B .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM