algorithmred-black-tree

Maximum height of a node in a red-black tree


If we have a node in a red-black tree with a black height of 3, what is the maximum height allowed for the node?


Solution

  • To maximise the height of that node, you'll want to create the longest downwards path possible with only 3 black nodes in it (excluding the starting node). As in red-black trees a red node cannot have a red child, the best you can do is to alternate the colors on such a path. Also, the path must end with a black node, since all (NIL) leaves are black. So the longest path with 3 black nodes is:

    node (black, but not counted in "black height")
       \
       red 
         \ 
         black #1
           \
           red
             \
             black #2
               \
               red
                 \
                 black #3/NIL
    

    The height (= length of path) is 6. It cannot be longer. So that is the maximum height of a node with a black height of 3. In general the maximum height of a node is the double of its black height.