Content deleted Content added
Nomen4Omen (talk | contribs) m →Deletion: <math>\text{y}</math>'s left child has been NIL before |
Nomen4Omen (talk | contribs) m →Deletion: narginally more explicit |
||
Line 155:
===Deletion===
Deletion of a node, say <math>\text{z}</math>, from a binary search tree <math>\text{T}</math> should abide three cases:{{r|algo_cormen|p=295}}
# If <math>\text{z}</math> is a leaf node, the parent
# If <math>\text{z}</math> has a single child node, the child gets elevated as either left or right child of{{nowrap| <math>\text{z}</math>
# If <math>\text{z}</math> has both a left and right child, the successor of <math>\text{z}</math> (let it be <math>\text{y}</math>) takes the position of <math>\text{z}</math> in the tree. This depends on the position of <math>\text{y}</math> within the BST:{{r|algo_cormen|p=296}}
##If <math>\text{y}</math> is {{nowrap|<math>\text{z}</math>
##If <math>\text{y}</math> is not the immediate right child of <math>\text{z}</math>, deletion proceeds by replacing the position of <math>\text{y}</math> by
The following pseudocode implements the deletion operation in a binary search tree.{{r|algo_cormen|p=296-298}}
|