5

Red-black trees are defined to have the following invariants:

  • The nodes are in sorted order (it is a binary search tree).
  • The root is black, and leaves are black.
  • Every red node has black children.
  • Every path to the root passes through the same number of black nodes.

There is also an obvious "empty" operation (just a leaf) and a more involved "insert" operation described on wikipedia, as well as an erase operation, and with some effort one can show that these operations preserve the red-black invariants just described.

My question is about the converse. Is it the case that:

  1. Every tree satisfying the red-black invariants is reachable by applying insert to empty with an appropriately chosen order of operations.
  2. Every tree satisfying the red-black invariants is reachable by applying insert or erase to empty with an appropriately chosen order of operations.

My guess is that the answer to 1 is "no" and the answer to 2 is "yes", but I have no proof of either case.

Mario Carneiro
  • 541
  • 2
  • 14

0 Answers0