notes81 - RedBlackTrees InsertionSummary ThreeCases Case1...

Info icon This 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
Image of page 1

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

View Full Document Right 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.
Image of page 2
Insert(1) Case 2: two consecutive red edges, sibling of first red is black, so rotation necessary.
Image of page 3

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

View Full Document Right 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.
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.
Image of page 5

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern