Content deleted Content added
Use BST-Successor in BST-Delete |
Qrwe~enwiki (talk | contribs) m Improve listing format in "Deletion" subsection. Tag: Reverted |
||
Line 154:
===Deletion===
Deletion of a node, say <math>\text{D}</math>, from a binary search tree <math>\text{BST}</math> should abide three cases:{{r|algo_cormen|p=295}}
<ol>
<li> If <math>\text{D}</math> has a single child node, the child gets elevated as either left or right child of {{nowrap|<math>\text{D}</math>'s}} parent depending on the position of <math>\text{D}</math> within the BST, as shown in fig. 2 part (a) and part (b), and as a result, <math>\text{D}</math> gets removed from the tree. <ul>
<li>If <math>\text{E}</math> is not the immediate right child of <math>\text{D}</math>, deletion proceeds by replacing the position of <math>\text{E}</math> by {{nowrap|<math>\text{E}</math>'s}} right child (here <math>\text{F}</math>), and <math>\text{E}</math> takes the position of <math>\text{D}</math> in <math>\text{BST}</math>, as shown here.<ref name="Algs4">According to Sedgewick ({{Cite book
|last1=Sedgewick
|first1=Robert
Line 171 ⟶ 173:
|url=http://algs4.cs.princeton.edu}})
the idea of this node exchange is due to T. Hibbard.</ref>
</ul>
</ol>
[[File:AVL-tree-delete.svg|600px|The node <math>\text{D}</math> to be deleted has 2 children]]
|