{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lecture23 - EXAMPLE(DONE IN CLASS AVL Trees Efficiency b It...

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

CSCI-255 Advanced Data Structures Lecture 23

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

View Full Document
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)
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

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

View Full Document

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

View Full Document
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 won’t be covering these (splay trees)...
View Full Document

{[ snackBarMessage ]}

### Page1 / 6

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

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

View Full Document
Ask a homework question - tutors are online