Search code examples
data-structurestreered-black-tree

Red black tree removal - why isn't this correct?


If I want to delete the 64 node from this Red Black Tree, I do the following:

https://i.sstatic.net/hAFy9.jpg

However, the visualization applet I'm using comes to this as result:

https://i.sstatic.net/3vFaS.jpg

Now I assume that they color 12 red after I make the 52 red, which then requires restructuring as they do. But why can't I simply make 52 black to maintain the black depth property? Isn't my final solution also correct?


Solution

  • No. In your solution, 54 has left black height 1 and right black height 0, making it invalid.