End of Term Review 1.4

End of Term Review 1.4 - AVL Trees AVL trees are balanced....

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: AVL Trees AVL trees are balanced. An AVL Tree is a binary search tree in which the heights of siblings can differ by at most 1. height 0 0 0 0 0 CSE 2011 Prof. J. Elder 0 0 - 16 - 0 0 Last Updated: 4/1/10 2:37 PM Height of an AVL Tree Claim: The height of an AVL tree storing n keys is O(log n). CSE 2011 Prof. J. Elder - 17 - Last Updated: 4/1/10 2:37 PM Insertion Imbalance may occur at any ancestor of the inserted node. height = 3 2 1 0 7 Insert(2) 1 4 1 3 0 height = 4 0 5 0 2 0 1 0 2 Problem! 4 1 3 0 1 0 8 0 0 5 0 0 0 CSE 2011 Prof. J. Elder 3 8 7 - 18 - Last Updated: 4/1/10 2:37 PM Insertion: Rebalancing Strategy Step 1: Search Starting at the inserted node, traverse toward the root until an imbalance is discovered. 3 2 1 2 height = 4 0 1 Problem! 4 1 3 0 7 8 0 0 5 0 0 CSE 2011 Prof. J. Elder - 19 - Last Updated: 4/1/10 2:37 PM Insertion: Rebalancing Strategy Step 2: Repair The repair strategy is called trinode restructuring. height = 4 7 3 nodes x, y and z are distinguished: z = the parent of the high sibling 3 y = the high sibling x = the high child of the high sibling 2 We can now think of the subtree rooted at z as consisting of these 3 nodes plus their 4 subtrees 1 2 Problem! 4 1 3 0 1 0 8 0 0 5 0 0 CSE 2011 Prof. J. Elder - 20 - Last Updated: 4/1/10 2:37 PM ...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Page1 / 5

End of Term Review 1.4 - AVL Trees AVL trees are balanced....

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online