10/29/15 1
AVL inser0on postcondi0on
When you insert into an AVL tree of height h, either
- you get a new tree with the same
height (which may have had rota0ons performed), or
- you get a tree that hasn’t had any
rota+ons performed on it, with an increased height of at most one When an insert is done in an AVL tree, nodes are checked one by one, moving up toward the root to make sure the height invariant con0nues to hold.
h h h h+1 h h-1 h-2 h h-2 h-1
How could a viola0on of the AVL height invariant happen at node T?
inser0on into a leK subtree could lead to a viola0on h+1 h h-2 h+1 h-2 h inser0on into a right subtree could lead to a viola0on (the red nodes violate the AVL height invariant)