Skip to main content Accessibility help
×
Hostname: page-component-77c89778f8-gvh9x Total loading time: 0 Render date: 2024-07-25T02:10:36.668Z Has data issue: false hasContentIssue false

5 - AVL Trees

Published online by Cambridge University Press:  10 November 2016

Shmuel Tomi Klein
Affiliation:
Bar-Ilan University, Israel
Get access

Summary

Bounding the Depth of Trees

We saw earlier that binary search trees are a good compromise between sequentially allocated arrays, which allow direct access, but are not updated easily, and linked lists, that support inserts and deletes in constant time, but cannot be searched efficiently. There is, however, still a major challenge left to be dealt with: the shape of the tree, and in particular its depth, on which ultimately all update complexities depend, is a function of the order in which the elements are processed. The same set of elements, when given in different orders, may produce completely different trees (see Figure 5.1).

Yet, we have generally no influence on the order the elements are presented, so we might get the worst case scenario, in which the depth of the tree is. This is unacceptable, as itwould also imply search and update times of the same order. Nothing has then be gained by passing from a linear linked list to a tree structure. What we would like is a tree structure for n elements in which the update times are guaranteed to be as close as possible to the optimal, which is log2n. Imposing, however, that the tree should be completely balanced, which yields the log2n bound on the depth, seems to be too restrictive: itwould require reshaping the tree constantly.

An elegant tradeoff has been suggested by Georgy Adelson-Velsky and Evgenii Landis and is known by the acronym of its inventors as AVL trees. The idea is to define a condition that on one hand is easily enforceable, but on the other hand yields trees that are almost balanced. Let us recall some definitions.

Background Concept: Depth of a Tree

The depth of a tree, sometimes also called its height, is the number of edges one has to traverse on the path from the root to a most distant leaf. The depths of the trees in Figure 5.1 are 1, 2 and 2, respectively. It is the number of levels minus 1, hence a tree consisting of a single node (the root is a leaf) has depth 0, and it is convenient to define the depth of an empty tree as −1.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2016

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • AVL Trees
  • Shmuel Tomi Klein, Bar-Ilan University, Israel
  • Book: Basic Concepts in Data Structures
  • Online publication: 10 November 2016
  • Chapter DOI: https://doi.org/10.1017/CBO9781316676226.006
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • AVL Trees
  • Shmuel Tomi Klein, Bar-Ilan University, Israel
  • Book: Basic Concepts in Data Structures
  • Online publication: 10 November 2016
  • Chapter DOI: https://doi.org/10.1017/CBO9781316676226.006
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • AVL Trees
  • Shmuel Tomi Klein, Bar-Ilan University, Israel
  • Book: Basic Concepts in Data Structures
  • Online publication: 10 November 2016
  • Chapter DOI: https://doi.org/10.1017/CBO9781316676226.006
Available formats
×