COT
lec19

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

• Notes
• 23

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

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)

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

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
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

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

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 )
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)

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

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 .
A-Node Let A be the nearest ancestor of the newly inserted node whose balance factor becomes +2 or –2 following the insert.

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

This is the end of the preview. Sign up to access the rest of the document.
• Spring '10
• sartajsahani
• Left-wing politics, balance factor, 23.2%

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern