Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AVL: Balanced Search Tree

Jim Counts
November 06, 2012

AVL: Balanced Search Tree

A presentation I created for CS 513 Fall 2012

Jim Counts

November 06, 2012
Tweet

More Decks by Jim Counts

Other Decks in Programming

Transcript

  1. BINARY SEARCH TREES CAN BECOME UNBALANCED ► We all love

    binary search trees ► Search, Insert, Delete are all in Θ(log ) ► But only on average ► Worst tree is completely unbalanced ► Unbalanced tree is the same as an array ► Θ() 0 1 2 0 1 2
  2. SELF-BALANCING TREES ► We want to preserve the good properties

    of a Binary Search Tree ► Efficiency ► Sorted Elements ► But Avoid Degeneration ► AVL Tree is one such implementation
  3. WHAT IS AN AVL TREE? ► Invented by these guys:

    AdelsonVelskii, M., & Landis, E. M. (1963). An algorithm for the organization of information. Defense Technical Information Center. ► AVL is a binary search tree ► Each node includes a “balance factor” ► Height balanced tree
  4. AN AVL • Balance Factor is the difference in heights

    of the sub trees • Empty tree = -1 • -1, 0, or +1
  5. NOT AN AVL This tree is a valid binary search

    tree, but it is not an AVL. The root does not have a valid value 2 ∉ {−1,0,1}
  6. EFFICIENCY DEPENDS ON HEIGHT ► And Height depends on :

    ► log2 ≤ ℎ < 1.4405 log2 ( + 2) − 1.3277 ► Something to do with Fibonacci and the golden ratio… ► This inequality suggested that search, insert and delete* operations would be in Θ(log ) ► Exact formula is unknown. ► Experiments show an approximation to 1.01 log2 + 0.1 ► So, on average, efficiency is comparable to BST
  7. DISCUSSION ►Are there any down sides? ►Why don’t we all

    just use AVL trees instead of plain old BST?