Docsity

Single Rotation - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Partial preview of the text

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

AVL Trees Introduction

  • 4.4 AVL trees

History Single Rotation Double Rotation Time Complexity Usage

History

  • An AVL (Adelson – Velskii and Landis) tree is a binary search tree with a balance condition.
  • A balance condition must be maintained and this ensures that the depth of the tree is O(log N).
  • ALV tree is a binary tree however we take into consideration that ever node in the tree the height of the left and the right sub tree can differ by at most 1.

Single Rotation

  • The book covers this point very clearly. page 120

Single rotation cont..

Perform Single Rotation

Example of Single Rotation

Double Rotation

  • Figure 4.34 in the book page

Double Rotation cont…

Double Rotation

Double Rotation cont…

Time Complexity

  • I would recommend that you go to this site to

better understand the time complexity, as well as a few more ideas on AVL trees.

  • http://www.ecf.utoronto.ca/apsc/courses/ece

242/2004spring/notes/bst2.pdf

Before the quiz

  • Insert these numbers into a AVL tree.
  • Remember AVL tree is a binary search tree but a tree that is balanced.
  • Important this is the same when you insert a node or when you delete a node.
  • Hence the difference of left sub tree and the right sub tree should be no more than h = 1.
  • Practice these inputs because we might have a quiz today .

Practice cont…

  • Here is the final tree!!!

• THE END