lecture23 - EXAMPLE (DONE IN CLASS) AVL Trees: Efficiency b...

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

View Full Document Right Arrow Icon
CSCI-255 Advanced Data Structures Lecture 23
Background image of page 1

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

View Full DocumentRight Arrow Icon
AVL Trees: Insert (cont’d) 1. Insert the node as in a BST 2. Starting at the newly inserted node, travel up the tree (towards the root), updating the balances along the way The first node for which the balance factor becomes +/- 2 (if any) is the root P of a subtree that needs to be rebalanced EXAMPLE: Insert the items 3, 2, 1, 4, 5, 6, 7, 16, 15, 14, 13, 12 into an initially empty AVL tree (DONE IN CLASS)
Background image of page 2
AVL Trees: Delete 1. Delete the node as in a BST 2. Starting at the parent of the deleted node, travel up the tree (towards the root), updating the balances along the way a. If the tree becomes unbalanced, decide which rotation needs to be performed, rotate the tree and update the balances b. Keep traveling towards the root, checking the balances. You may need to rotate again
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

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

Unformatted text preview: EXAMPLE (DONE IN CLASS) AVL Trees: Efficiency b It can be shown that the worst case height of an AVL tree is at most 44% larger than the minimum possible for a BST (i.e. approximately 1.44lgn) Time Complexity of Basic AVL Tree Operations b Insert s Maximum possible number of rotations = 1 b Delete s Maximum possible number of rotations = lg( n ) b Worst case times s Search: O(lg n ) s Insert: O(lg n ) s Delete: O(lg n ) Conclusions b AVL trees maintain balance of BSTs while they are being created via insertions of data b An alternative approach is to have trees that readjust themselves when data is accessed, making often accessed data items move to the top of the tree. We wont be covering these (splay trees)...
View Full Document

Page1 / 6

lecture23 - EXAMPLE (DONE IN CLASS) AVL Trees: Efficiency b...

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

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