{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
1 AVL Trees
Image of page 1

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

View Full Document Right 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
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.
Image of page 3

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

View Full Document Right 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
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.
Image of page 5

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

View Full Document Right Arrow Icon
6 AVL Trees: Examples
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
Image of page 7

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

View Full Document Right 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
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).
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern