I think this is the easiest algorithm to learn and code. Robert Sedgewick’s Java code is always succinct. I have learnt how to code Tries based on his code. Now his Red-black tree code is easy to remember.

Now this tree has to be fixed so that it conforms to the rules that govern a Red-Black tree. So I code a method to fix it. This method is based on the pseudo-code from the same book. But I think there is a bug which I haven’t found. This tree after it is fixed looks like this.

The black height property is 2.

The black height property for the left branch is 2 but it is 3 for one of the paths on the right.

I may have to read some other book because finding this bug is going to be hard.