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.
CodePudding user response:
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
.