algorithmbinary-treebinary-search-treered-black-treered-black-tree-insertion

Explain why insertion (and the different cases) don't change black height of red black trees


red black tree - insertion - z's uncle is red

Why is black height of node γ(gamma, the top most node) is unchanged after the operation?

I know how to explain why black height of T1 - T4 is the same after operation. But for gamma, I have absolutely no clue.

Anyone has ideas?


Solution

  • Okay so the insert of Alpha was done and it was coded red. Now after the insert the RB tree insertion code will check for imbalance between the red and black colors to determine if a rotation has to take place. After the check the Beta node was turned black, the Y node turned red and the gamma node turned black thereby keeping the tree RB balanced without need of rotation.

    https://en.wikipedia.org/wiki/Red%E2%80%93black_tree

    please see above wiki link to get a full explanation of how the color switches happen and why and how it helps determine rotation/s needed.