-1

I know there are two cases which uncle is black in red black trees when inserting a new node. But in all the cases parent is red. if parent is black there is no violation. what shall I do in such situation in a red black tree?

Lakindu Akash
  • 964
  • 1
  • 11
  • 28

1 Answers1

1

If you end up adding a node into a red/black tree and its parent is black, you can just make the node red and call it a day. There’s no need for any fixup. If you look at the rules for red/black trees, this doesn’t cause any new violations because all root-null paths still go through the same number of black nodes.

A different perspective: if you think of red/black trees as an isometry or 2-3-4 trees, then this rule corresponds to taking a leaf with one key in it and adding in another key, which doesn’t require any further fixup steps.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065