I was asked this question in an exam, but I'm not really convinced with the answer from the teacher, and I would like to ask what do you think about it.
A rotation on a red-black tree...
- preserves the black height of all nodes.
- preserves in-order ordering.
Which above the above statements are true:
A. (1) alone
B. (2) alone
C. Both (1) and (2)
D. Neither (1) nor (2).
The teacher claims a rotation doesn't preserve the black height, and the answer is B: it preserves in-order ordering only. However, I strongly believe that it preserves the black height of all nodes and the answer is C, not B.
Am I right or is my teacher right?
Your teacher is right. On Wikipedia we find an example of a rotation at "insert case 5":
The left side is a simple variant, and the right side a more elaborate case.
The second row shows the result of a rotation. It is clear that as the black root moved to the right subtree, the nodes in the left subtree lose a black node on their paths, and so there is a black violation.
Note that after such a rotation there often is a way to change the color of one or more nodes to resolve the black violation. This is what is pictured in the bottom row of the image. But this action is not part of the rotation.