Proof: To do this first show that a tree rooted at x contains at least 2bh(x)-1 internal nodes. By Induction: Base case: Any tree of height 0 is a leaf node, x and has at least has bh(x) = 0, (this is a NIL node) 20-1 = 1 -1 = 0 internal nodes. Assume true for all heights less than h. Given an internal node, x, with bh(x), at height h each child must have either bh(x), or bh(x)-1 This depends on the color of the child. The heights of the children are one less than the height of x Therefore by the induction hypothesis, each of the children have 2bh(x)-1-1 internal nodes. threfore x has at least 2bh(x)-1-1+ 2bh(x)-1-1 + 1 = 2bh(x)-1 internal nodes. By property 3 at least 1/2 of the nodes on any path must be black There fore the black height of the root must be at least h/2 n >= 2h/2-1 lg(n-1) >= h/2 2lg(n-1) >= h
RotateLeft(T,x) ( 1) y = x.rightChild() ( 2) x.right = y.leftChild() ( 3) if (y.leftChild() != NIL) ( 4) y.leftChild(y).parent = x ( 5) y.parent = x.parent() ( 6) if x.parent() = NIL ( 7) T.root = y ( 8) else ( 9) if x = x.parent().leftChild() (10) x.parent().left = y (11) else (12) x.parent().right = y (13) y.left = x (14) x.parent = y find y move T2 to become x's right child reparent things move x to be y's right child
( 1) TreeInsert(T,x) ( 2) x.color = red ( 3) while x != T.root() and color x.parent().color == red ( 4) if x.Parent() = x.parent().parent().leftChild() ( 5) then y = x.parent().parent().right ( 6) if y.color() == red ( 7) x.parent().color = black // all case I ( 8) y.color = black ( 9) x.parent().parent().color = red (10) x = x.parent().parent() (11) else if x == x.parent().rightChild() (12) x = x.parent() // case II (13) LeftRotate(T,x) (14) x.parent().color = black // case III (15) x.parent().parent().color= red (16) RightRotate(T,x) (17) else (18) repeat lines 5-16, replace right with left and left with right (19) T.root().color = black