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

Info icon This 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)
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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 )
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)
Image of page 5

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

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

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern