{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

1 AVL Trees

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

View Full Document
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
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.

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

View Full Document
4 Imbalanced Tree 70 60 90 30 20 110 80 70 60 90 30 10 20 110 An Imbalanced Tree A Balanced Tree
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.

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

View Full Document
6 AVL Trees: Examples
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

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

View Full Document
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
9 ADT AVL Tree Operations: 1. Method FindKey (int tkey, boolean found). 2. Method Insert (int k, Type e, boolean inserted).

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern