This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Outline • BST: insertion, deletion, search • AVL tree: deﬁnition • AVL tree: insert • AVL tree: delete • AVL tree maintenance: rotations Lecture 8, AVL Tree p. 1 Basic Operations on BST Find:
• Compare to the value at root • If not at the root, recursively ﬁnd in the appropriate subtree • Stop when an empty tree is reached Insert:
• Search until the empty subtree is reached • Replace the empty subtree with a node containing the value Delete:
• Search the value • If the value is at a leaf, delete the leaf • If the value is at a node with one child, delete the node, and promote its child • If the value is at a node with two children, move the value in the predecessor (or successor) into this node, delete its predecessor (or successor) Lecture 8, AVL Tree p. 2 Rotations: Single Rotation x y y Tc
right−rotate(x) Ta x Ta Tb left−rotate(y) Tb Tc Lecture 8, AVL Tree p. 3 Rotations: Double Rotation
2 x z 1 y z Tc y x Ta Tb1 Tb2 1: left−rotate(y) 2: right−rotate(x) Ta Tb1 Tb2 Tc Lecture 8, AVL Tree p. 4 An Example 7 3 8 2 5 9 0
Insert(1) Delete(8) 4 6 Lecture 8, AVL Tree p. 5 ...
View
Full
Document
This note was uploaded on 07/17/2010 for the course CS 240 taught by Professor Ortiz during the Spring '09 term at Waterloo.
 Spring '09
 ORTIZ

Click to edit the document details