
RedBlack Tree Denition Redblack trees have the following prop erties Every no de is colored either red orblack Every leaf NIL p ointer is black If a no de is red then b oth its children are black Every single path from a no de to a decendant leaf contains the same number of black no des What do es this mean If the ro ot of a redblack tree is black can we just color it red No Foroneof its children might b e red If an arbitrary no de is red can we coloritblack No Because now all no des may not have the same black height What tree maximizes the numberofnodes in a tree of black height h What do es a redblack tree with two real no des lo ok like (1) (2) (3) (4) Not consecutive reds Not NonUniform black height RedBlack Tree Height Lemma A redblack tree with n internal no des has height at most lg n Pro of Our strategy rst we bound the number of no des in any subtree then webound the height of any subtree We claim that any subtree ro oted at x has at least bhx internal no des where bhxisthe black height of no de x Pro of byinduction bhx x is a leaf Now assume it is true for all tree with black height bhx If x is black b oth subtrees have black height bhx If x is red the subtrees have black height bhx Therefore the numberof internal no des in any subtree is bhx bhx bhx n Now let h be the height of our redblack tree At least half the no des on any single path from ro ot to leaf must b e black if we ignore the ro ot h h Thus bhx handn so n This implies that lgn hso h lgn Therefore redblack trees have height at most twice optimal We have a balanced search tree if we can maintain the redblack tree structure under insertion and deletion.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-