{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

14-1. AVLTrees_outside

# Nh 2nh 2 nh 4nh 4 nh 8nn 6 by induction nh 2 i nh 2i

This preview shows pages 3–7. Sign up to view the full content.

n(h) > 2n(h-2), n(h) > 4n(h-4), n(h) > 8n(n-6), … (by induction), n(h) > 2 i n(h-2i) Solving the base case we get: n(h) > 2  h/2-1 Taking logarithms: h < 2log n(h) +2 Thus the height of an AVL tree is O(log n) 3 4 n(1) n(2)

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

View Full Document
©  2004 Goodrich, Tamassia AVL Trees 4 Insertion Insertion is as in a binary search tree Always done by expanding an external node. Example: 44 17 78 32 50 88 48 62 54 w b=x a=y c=z 44 17 78 32 50 88 48 62 before insertion after insertion
©  2004 Goodrich, Tamassia AVL Trees 5 Trinode Restructuring let ( a , b , c ) be an inorder listing of  x y z perform the rotations needed to make  b  the topmost node of the  three b=y a=z c=x T 0 T 1 T 2 T 3 b=y a=z c=x T 0 T 1 T 2 T 3 c=y b=x a=z T 0 T 1 T 2 T 3 b=x c=y a=z T 0 T 1 T 2 T 3 case 1: single rotation (a left rotation about a ) case 2: double rotation (a right rotation about c , then a left rotation about a ) (other two cases are symmetrical)

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

View Full Document
©  2004 Goodrich, Tamassia AVL Trees 6 Insertion Example, continued 88 44 17 78 32 50 48 62 2 5 1 1 3 4 2 1 54 1 T 0 T 2 T 3 x y z 2 3 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page3 / 11

nh 2nh 2 nh 4nh 4 nh 8nn 6 by induction nh 2 i nh 2i...

This preview shows document pages 3 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online