{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

notes33

# notes33 - Name Sahil Gulati Week Feb 18th 20th 22nd AVL...

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

Name: Sahil Gulati Week: Feb 18th, 20th, 22 nd AVL Trees - An AVL tree is a balanced binary tree - For every internal node n of the tree the height of the children of n can differ at most by 1 Height of leafs = 0 Height of n = 1 + max(height of left or right node) 3-1 > 1 Not an AVL tree Height of an AVL tree Proposition: Total height of an AVL tree is O(log n) where n is the number of nodes Proof : Find the tree that has the minimum number of nodes for height h n (h) = number of internal nodes of tree with the minimum number of nodes with height h n (1) = 1 n (2) = 2 n (3) = 4 h

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

View Full Document
In general the AVL tree with height h and minimum number of nodes contains a sub tree of height h-1 and another one of height h-2 with minimum number of nodes n (n) = n (n-1) + n (n-2) + 1 n (n) > n (n-1) + n (n-2) Since n (n-1) > n (n-2) n (h) > 2n (h-2) n (h) > 4n (h-4) n (h) > 8n (h-6) n (h) > 2 i n (h-2i) n (h) > 2 x n (0) h - 2x = 0, x = h/2 n (h) > 2 h/2 log n > h/2 2log n > h h = O(log n) Insertion in an AVL tree
Insert (54) - Find position to insert the following path from the root - Insert node instead of the leaf not an AVL tree as } 3 – 1 > 1 - Starting at the inserted node and going upwards to the root rotate the nodes n; the following way if the sub tree of that node is unbalanced - Identify the following nodes z – node that is root to an unbalanced sub tree y – the child of z with the largest height x – the child of y with the largest height

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

View Full Document
- Rename z, y and x as a, b and c based on the value of the keys from minimum to maximum a b c z x y 50 54 63 -
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}