views:

66

answers:

1

I am trying to understand how red black trees work, assume the transition from first to the second at the picture, I get it this without any problem, after this according to teaching resources, I need to do a local fix on the red G node. So as a fix to the 2nd step, does G simply colored to black to maintain the red-black properties ?

alt text

thanks

+1  A: 

The classic definition says the root has to be black, so it would have to be painted black to get that property. The basic idea is that red nodes are forbidden in certain locations (such as being a child of another red node), so painting a node red creates a potential constraint violation that should be checked for.

Victor Nicollet