60 likes | 252 Views
COP 3503 - Computer Science II (Fall 2005) Week Eight. By Yunjun Zhang. AVL tree. Named after its discoverers, Adelson-Velskii and Landis) It is a BST with balance conditions. Depth log(N) Definition BST
E N D
COP 3503 - Computer Science II (Fall 2005)Week Eight By Yunjun Zhang
AVL tree • Named after its discoverers, Adelson-Velskii and Landis) • It is a BST with balance conditions. • Depth log(N) • Definition • BST • For any node in the tree, the difference between the height of left subtree and right subtree is at most 1
AVL tree • Properties • An AVL tree of height H has at least FH+3-1 nodes, where Fi is the ith Fibonacci number. • Proof : on board.
AVL tree • Ideas behind AVL tree • Balance conditions are violated when insertion or deletion operate. • Rotations must be performed to maintain the balance condition. • Single/Double rotation. Symmetric for left or right version.
AVL tree • Insertion • Single Rotation • Double Rotation • On board
AVL tree • Deletion • Delete the node as in a binary search tree. • The node deleted will be either a leaf or have just one subtree.