redblk8 - Advanced Tree Structures Red-Black Trees...

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

View Full Document Right Arrow Icon
Introduction This set of notes in intended to clarify (possibly simplify) some of our previous discussions about red-black trees. Clearly, the most difficult concept regarding red-black trees is the re-balancing that occurs after insertion or deletion in the tree. This set of notes will focus only on these aspects of red-black trees; see the original set of notes for other details regarding this data structure. Definition and Example for Reference A red-black tree is defined as: 1. A binary search tree. 2. The root and all external nodes are colored black. 3. No root-to-external-node path has two consecutive red nodes. 4. All root-to-external-node paths have the same number of black nodes. Figure 1 illustrates an example red-black tree. Figure 1 – A red-black tree Notice that the tree in Figure 1 satisfies all of the properties of a red-black tree. Namely, (1) it is a BST, (2) the root and all external nodes are colored black, (3) no root-to-external-node path has two consecutive red nodes, and (4) all root-to- external-nodes paths contain the same number of black nodes; two in this Red-Black Trees Revisited - 1 Advanced Tree Structures – Red-Black Trees Revisited (8) 6 5 8 7 6 1 5 6
Background image of page 1

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

View Full DocumentRight Arrow Icon
example. (Applying the alternate definition we have: every path from the root to an external node has exactly two black pointers and three black nodes (including the root and the external node); and no such path has two consecutive red pointers.) Insertion into a Red-Black Tree Recall from our earlier discussions that a new node, upon insertion, is colored red . This is because insertion of a new black node is guaranteed to cause a violation of property #3. Since all new nodes are initially red nodes, this leads to a total of eight different insertion situation in which an imbalance in the tree can occur. Recall that not all insertions of red node will cause an imbalance. The imbalances that can occur due to an insertion can be categorized into two categories depending upon the configuration of the existing tree into which the insertion occurs. Let’s assume that u is the newly inserted red node, pu is its parent, and gu is the grandparent of u and the parent of pu . Since we know that the tree in which the insertion is to take place is a valid red-black tree we know that all four of the properties for red-black trees hold. We also know that any insertion is occurring as a new leaf node (not counting the external nodes). This means that the subtree in which the insertion is occurring is already balanced and if the insertion causes it to become imbalanced it can do so no further than two levels above the new node in the tree, i.e., at its grandparent level. Therefore, since the imbalance occurs (if it occurs at all) within the subtree rooted at the grandparent then we need to be concerned with the color of the grandparents’ other child (the child of gu which is not pu ). If the other child of gu is red there are four cases to consider: LRr, LLr, RRr, and RLr Each of these four types of imbalances is shown in Figure 2.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/13/2011.

Page1 / 18

redblk8 - Advanced Tree Structures Red-Black Trees...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online