Lecture11 - Other Balanced Trees, and an Unbalanced One...

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: 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

Page1 / 23

Lecture11 - Other Balanced Trees, and an Unbalanced One...

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