3

From the property of Red-Black Trees we know that:

  • All leaves (NIL) are black. (All leaves are same color as the root.)(Comren et al "Introduction to Algorithms")

An example of a red–black tree. From Wikipedia

But what is the reason that we should enforce them as Black, even though they're NILL's?

Raphael
  • 73,212
  • 30
  • 182
  • 400

2 Answers2

3

Take a uncolored leaf node, now you can color it as either red or black. If you colored it as red then you may have chance that your immediate ancestor is also red which is contradicting(according to basic principle). If you color it as black then no problem even though the immediate ancestor is red. And also no change in the number of black nodes from root to leaf paths(i.e every path get +1). This may be the possible reason behind that.

Siva Krishna Aleti
  • 426
  • 1
  • 4
  • 10
3

It's simply a part of the definition of a red-black tree. It is also necessary to maintain one of the other rules associated with red-black trees: If a node is red, then both its children are black.

FrankW
  • 6,609
  • 4
  • 27
  • 42
Chicachu
  • 31
  • 1