Lect7 - AVL Trees 1 AVL Trees Consider a situation when...

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

View Full Document Right Arrow Icon
1 AVL Trees
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 AVL Trees Consider a situation when data elements are inserted in a BST in sorted order: 1, 2, 3, … BST becomes a degenerate tree . Search operation FindKey takes O(n), which is as inefficient as in a list. 1 2 3 n
Background image of page 2
3 AVL Trees It is possible that after a number of insert and delete operations a binary tree may become imbalanced and increase in height. Can we insert and delete elements from BST so that its height is guaranteed to be O(log n)? Yes, AVL Tree ensures this. Named after its two inventors: A delson- V elski and L andis.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Imbalanced Tree 70 60 90 30 20 110 80 70 60 90 30 10 20 110 An Imbalanced Tree A Balanced Tree
Background image of page 4
5 AVL Tree: Definition Height-balanced tree: A binary tree is a height-balanced-p-tree if for each node in the tree, the difference in height of its two subtrees is at the most p. AVL tree is a BST that is height-balanced- 1-tree.
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 AVL Trees: Examples
Background image of page 6
7 AVL Trees 1 2 3 4 5 Inserting 1, 2, 3, 4 and 5 2 3 4 1 5 BST after insertions AVL Tree after insertions
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 ADT AVL Tree Elements: The elements are nodes, each node contains the following data type: Type Structure: Same as for the BST; in addition the height difference of the two subtrees of any node is at the most one. Domain: the number of nodes in a AVL is bounded; type AVLTree
Background image of page 8
9 ADT AVL Tree Operations: 1. Method FindKey (int tkey, boolean found). 2. Method Insert (int k, Type e, boolean inserted).
Background image of page 9

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

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

This note was uploaded on 05/18/2010 for the course COMPUTER S CSC212 taught by Professor Shah during the Winter '09 term at King Saud University.

Page1 / 34

Lect7 - AVL Trees 1 AVL Trees Consider a situation when...

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

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