Docsity

Advanced Data Structures - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Partial preview of the text

Download Advanced Data Structures - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

AVL TREES

By Asami Enomoto

CS 146

AVL Tree is…

  • named after A delson- V elskii and L andis
  • the first dynamically balanced trees to be propose
  • Binary search tree with balance condition in which the sub-trees of each node can differ by at most 1 in their height

An AVL tree has the following properties:

  1. Sub-trees of each node can differ by at most 1 in their height
  2. Every sub-trees is an AVL tree

AVL tree?

YES Each left sub-tree has height 1 greater than each right sub-tree

NO Left sub-tree has height 3, but right sub-tree has height 1

Single Rotation

left sub-tree is two level deeper than the right sub-tree

move ① up a level and ② down a level

Double Rotation

Left sub-tree is two level deeper than the right sub-tree

Move ② up two levels and ③ down a level

Deletion

  • Delete
    • Imbalance at
    • Perform rotation with
  • Imbalance at
  • Perform rotation with

Key Points

  • AVL tree remain balanced by applying rotations, therefore it guarantees O(log N) search time in a dynamic environment
  • Tree can be re-balanced in at most O(log N) time