Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a red node have just 1 black child in a red-black tree?

The rules for a Red-Black Tree:

  1. Every node is either red or black.
  2. The root is black.
  3. Every leaf (NIL) is black.
  4. If a node is red, then both its children are black.
  5. For each node, all simple paths from the node to descendant leaves contain the same number of black nodes.

Rule 4 mentions that red nodes need both black childs but what if there is just one child to begin with? Is there an argument to prove or disprove this?

like image 521
sanic Avatar asked Oct 15 '25 04:10

sanic


1 Answers

No,a red node cannot have one child,consider the following cases:- 1.If the single child it has is red...this cannot happen because no two consecutive nodes can be red. 2.If the child is black...again this cannot happen because this would violate the 'Black Height Rule'...this case would give one extra black node in a path which is not correct according to the rule.

like image 178
Ehsaas Avatar answered Oct 18 '25 06:10

Ehsaas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!