notes81

notes81 - RedBlackTrees InsertionSummary

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

View Full Document Right Arrow Icon
Red-Black Trees Insertion Summary Insertion is always at the bottom of the tree Incoming edge of new node is red and incoming edges for the leafs are black Three Cases: Case 1: No rule is broken (no two consecutive red edges). No action required. Case 2: Two consecutive red edges. The sibling of the first red edge is black. Case 3: Two consecutive red edges. The sibling of the first red edge is red. In all cases, continue fixing until the top of the tree is reached. Example 1: Initial tree
Background image of page 1

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

View Full DocumentRight Arrow Icon
Insert(3) Case 1: no changes required. Insert(20) Case 2: two consecutive red edges, sibling of first red is black, so rotation necessary.
Background image of page 2
Insert(1) Case 2: two consecutive red edges, sibling of first red is black, so rotation necessary.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Insert(19) Case 3: two consecutive red edges, sibling of first red is red, so recoloring necessary. Case 2: two consecutive red edges, sibling of first red is black, so rotation necessary.
Background image of page 4
Final tree Deletion Remember that in AVL Trees when we had to remove a node in the middle of the tree, we had to swap it with the rightmost grandchild in the left subtree. As in AVL Trees, deletion ALWAYS happens in the internal nodes that are at the bottom. If the node to remove is not at the bottom, we swap the node to remove with the rightmost child in the left subtree.
Background image of page 5

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

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

Page1 / 10

notes81 - RedBlackTrees InsertionSummary

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