Lecture11

# Lecture11 - Other Balanced Trees and an Unbalanced...

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

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: Other Balanced Trees, and an Unbalanced One (Huffman Encoding) EECS 233-2- Previous Lecture AVL trees (self-balancing binary tree) Rotation operations: left rotation, right rotation, double rotation-3- Previous Lecture Insertion may cause change of balance value Insertion algorithm Insert a node, which may cause a change to balance values For each ancestor (from the leaf to the root), if the balance value changes from +/-1 to 0, DONE changes from 0 to +/- 1, go to the next ancestor changes from +/-1 to +/- 2, rebalance this tree, DONE How to balance the tree? If insertion occurred in the left-left subtree, do right rotation right-right subtree, do left rotation left-right subtree, do left-right double rotation -3- Previous Lecture Insertion may cause change of balance value Insertion algorithm Insert a node, which may cause a change to balance values For each ancestor (from the leaf to the root), if the balance value changes from +/-1 to 0, DONE changes from 0 to +/- 1, go to the next ancestor changes from +/-1 to +/- 2, rebalance this tree, DONE How to balance the tree? If insertion occurred in the left-left subtree, do right rotation right-right subtree, do left rotation left-right subtree, do left-right double rotation right-left subtree, do right-left double rotation-4- Deletion from AVL Trees Deletion may also cause unbalanced subtrees; if a deletion causes a change to the height, the ancestors need to be checked or balanced. Deletion algorithm remove the node (leaf or non-leaf, remember how it works? ) Ultimately causes removal of a node X with 0 or 1 child May cause a change of the balance values for X ’ s parent For each ancestor (from X ’ s parent to the root), if the balance value changes from +/-1 to 0, what to do?...
View Full Document

## This note was uploaded on 04/07/2008 for the course EECS 233 taught by Professor Rabinovich during the Spring '08 term at Case Western.

### Page1 / 23

Lecture11 - Other Balanced Trees and an Unbalanced...

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

View Full Document
Ask a homework question - tutors are online