# AVLdelete - Deletion from an AVL Tree First we will do a...

This preview shows pages 1–3. Sign up to view the full content.

Deletion from an AVL Tree First we will do a normal binary search tree delete. Note that structurally speaking, all deletes from a binary search tree delete nodes with zero or one child. For deleted leaf nodes, clearly the heights of the children of the node do not change. Also, the heights of the children of a deleted node with one child do not change either. Thus, if a delete causes a violation of the AVL Tree height property, this would HAVE to occur on some node on the path from the parent of the deleted node to the root node. Thus, once again, as above, to restructure the tree after a delete we will call the restructure method on the parent of the deleted node. One thing to note: whereas in an insert there is at most one node that needs to be unbalanced, there may be multiple nodes in the delete that need to be rebalanced. At any point in the restructuring algorithm ONLY one node will ever be unbalanced. What may happen is when that node is fixed, it may propagate an error to an ancestor node. But, this is NOT a problem because our restructuring algorithm goes all the way to the root node, removing any problems as they appear, one by one.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Choosing the Nodes A, B and C for a Delete Restructuring One thing that is more complicated about choosing the nodes A, B and C for the AVL Tree delete restructuring is that these nodes are NOT from the ancestral path followed from the origin of the delete. Clearly, if a delete will cause an imbalance, it will be because the subtree that contains the deleted node has become too short. (Since this subtree can only get “shorter” and the previous version of the tree was balanced, the only possible imbalance is caused when this tree goes from a height of k-1 to k-2, where k is the height of the tree on the other side.) Remember that the nodes A, B and C are always on the “longest” path to the bottom of the tree. This means that when we find an imbalanced node after deleting, the node to the
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 09/21/2011.

### Page1 / 12

AVLdelete - Deletion from an AVL Tree First we will do a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online