Why the leaf node in red black tree is NIL?

772 views Asked by At

I feel confused when learning Red Black Tree,actually I don't know why we need NIL as leaf in the tree and it seems useless.Could any one can help me?Thanks in advance:)

1

There are 1 answers

0
Andreas DM On

The main reason it has NIL is to always balance the tree, two children per parent for example. If it wasn't properly balanced, in the worst case it would just be a glorified linked list not getting the benefits of a red black tree.