1 / 11

AVL Trees

AVL Trees. And the pain you must suffer to learn them. The AVL Property. For every node the left and right side differ in height by less than two. The left and right side are themselves AVL trees. How Balanced is That?. AVL trees might end up kinda 'sparse'.

eliora
Télécharger la présentation

AVL Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AVL Trees And the pain you must suffer to learn them

  2. The AVL Property • For every node the left and right side differ in height by less than two. • The left and right side are themselves AVL trees.

  3. How Balanced is That? • AVL trees might end up kinda 'sparse'. • The worst case height of an AVL tree with n nodes is about 1.44log(n). • Discussion at http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/AVL.html

  4. Rotations • Rotations are to rearrange nodes to maintain AVLness. • They are needed on insert and delete.

  5. Names of Rotations • There are four of them • Single Left (LL) and Single Right (RR) • Double Left (LR) and Double Right (RL) • The names describe which way the node moves. For example, a left rotation moves the node down and left. • Nodes always move down when rotated.

  6. How To Do Single Rotations

  7. A Left Rotation via Pointers temp=p->right ; p->right=temp->left ; temp->left=p ; p=temp ;

  8. Double Rotation • A LR double rotation is to rotate something to the left, and then its former parent to the right. • A RL double rotation is to rotate something to the right, and then its former parent to the left.

  9. Rotation Examples • All the rotations in picture form http://sky.fit.qut.edu.au/~maire/avl/System/AVLTree.html • All the rotations in pictures and text http://www.cs.jcu.edu.au/Subjects/cp2001/1997/foils/balancedTrees/balancedTrees.html • Sample single and double rotationshttp://ironbark.bendigo.latrobe.edu.au/courses/subjects/DataStructures/mal/session200/lecture.html

  10. The AVL Insertion Algorithm • An Intuitive description can be found at http://www.ucfv.bc.ca/cis/watkissc/200009/200009Comp175/notes/avlTrees.html

  11. The AVL Game • Play the game http://www.seanet.com/users/arsen/avltree.html

More Related