Adelson-Velsky and Landis trees (AVL)

Published

2023-08-05

Before we begin with AVL trees, watch this short video on tree rotation. We’ll use tree rotation with AVL trees and later on with splay trees, so it’s important you understand what’s going on with this operation.

Now we can proceed with AVL trees.

AVL trees are a kind of balanced binary search tree, invented in 1962 by Adelson-Velsky and Landis. Balancing avoids pathological structures and keeps performance for search, insert and delete at \mathcal{O}(\log N).

Here’s an introduction to AVL trees.

Here are some visualizations to help you get a feel for rotations.

Use the algorithm visualization tool. Try performing this sequence of insertions: 5, 4, 7, 6, 10, 9. Why does the insertion of 9 cause a problem? What kind of rotation takes place? What does the resulting tree look like?

AVL tree visualization

Resources

Comprehension check:

  1. True or false? An AVL tree is a self-balancing tree.
  2. For each node in an AVL tree, the heights of the left and right subtrees can differ by at most _______.
  3. We preserve the AVL property when adding and deleting nodes by performing the appropriate ____________.
  4. True or false? To determine the appropriate rotation, we must first find the node that violates the AVL property.
  5. True or false? A “zig-zig” case occurs when the path from the problem node to it’s most distant leaf first passes through two right children or two left children.
  6. In a “zig-zag” case, we perform a ____________ rotation.

Answers: ǝlqnop / ǝnɹʇ / ǝnɹʇ / uoᴉʇɐʇoɹ / Ɩ / ǝnɹʇ

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

All materials copyright © 2020–2023, The University of Vermont. All rights reserved.