AVLTrees

AVLTrees - AVL Trees 1 AVL Trees 6 3 8 4 v z AVL Trees 2...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: AVL Trees 1 AVL Trees 6 3 8 4 v z AVL Trees 2 AVL Tree Definition (9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that for every internal node v of T, the heights of the children of v can differ by at most 1 . 88 44 17 78 32 50 48 62 2 4 1 1 2 3 1 1 An example of an AVL tree where the heights are shown next to the nodes: AVL Trees 3 Height of an AVL Tree Fact : The height of an AVL tree storing n keys is O(log n). Proof : Let us bound n(h): the minimum number of internal nodes of an AVL tree of height h. We easily see that n(1) = 1 and n(2) = 2 For n > 2, an AVL tree of height h contains the root node, one AVL subtree of height n-1 and another of height n-2. That is, n(h) = 1 + n(h-1) + n(h-2) Knowing n(h-1) > n(h-2), we get n(h) > 2n(h-2). So 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)...
View Full Document

Page1 / 2

AVLTrees - AVL Trees 1 AVL Trees 6 3 8 4 v z AVL Trees 2...

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

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