lec19 - AVL Trees binary tree for every node x, define its...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
AVL Trees binary tree for every node x , define its balance factor balance factor of x = height of left subtree of x – height of right subtree of x balance factor of every node x is – 1 , 0 , or 1 log 2 (n+1) <= height <= 1.44 log 2 (n+2)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Example AVL Tree 0 0 0 0 1 0 -1 0 1 0 -1 1 -1 10 7 8 3 1 5 30 40 20 25 35 45 60
Background image of page 2
put(9) 0 0 0 0 1 0 -1 0 1 0 -1 1 -1 9 0 -1 0 10 7 8 3 1 5 30 40 20 25 35 45 60
Background image of page 3

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

View Full DocumentRight Arrow Icon
put(29) 0 0 0 0 1 0 0 1 0 -1 1 -1 10 7 8 3 1 5 30 40 20 25 35 45 60 29 0 -1 -1 -2 RR imbalance => new node is in right subtree of right subtree of white node (node with bf = 2 )
Background image of page 4
0 0 0 0 1 0 0 1 0 -1 1 -1 10 7 8 3 1 5 30 40 25 35 45 60 0 RR rotation. 20 0 29 put(29)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Insert/Put Following insert/put, retrace path towards root and adjust balance factors as needed. Stop when you reach a node whose balance factor becomes 0 , 2 , or –2 , or when you reach the root. The new tree is not an AVL tree only if you reach a node whose balance factor is either 2 or –2 . In this case, we say the tree has become unbalanced .
Background image of page 6
Let A be the nearest ancestor of the newly inserted node whose balance factor becomes
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/07/2010 for the course COT 5536 taught by Professor Sartajsahani during the Spring '10 term at University of Florida.

Page1 / 23

lec19 - AVL Trees binary tree for every node x, define its...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online