next up previous
Next: 4.4.1 Average Case Analysis of BST Operations Up: 4. Binary Trees Previous: 4.3.2 Sketch of Huffman Tree Construction

4.4 Binary Search Tree


  
Figure 4.14: An example of a binary search tree
\begin{figure}
\centerline{\psfig{figure=figures/Fbstexample.ps}}
\end{figure}

Deletion in BST

Let x be a value to be deleted from the BST and let X denote the node containing the value x. Deletion of an element in a BST again uses the BST property in a critical way. When we delete the node X containing x, it would create a "void" that should be filled by a suitable existing node of the BST. There are two possible candidate nodes that can fill this void, in a way that the BST property is not violated: (1). Node containing highest valued element among all descendants of left child of X. (2). Node containing the lowest valued element among all the descendants of the right child of X. In case (1), the selected node will necessarily have a null right link which can be conveniently used in patching up the tree. In case (2), the selected node will necessarily have a null left link which can be used in patching up the tree. Figure 4.15 illustrates several scenarios for deletion in BSTs.

  
Figure 4.15: Deletion in binary search trees: An example
\begin{figure}\centerline{\psfig{figure=figures/Fdelbst.ps}}
\end{figure}



 
next up previous
Next: 4.4.1 Average Case Analysis of BST Operations Up: 4. Binary Trees Previous: 4.3.2 Sketch of Huffman Tree Construction
eEL,CSA_Dept,IISc,Bangalore