1

What is the maximum number of rotations while inserting a new element into n-element Red Black Tree?

If I'm correct, insertion that does not violate rules of RBT requries maximum of 2 rotations (2 cases). Assuming that's it, is O(1) also a correct answer?

If that's right, confirm it and please tell me, what requires maximum of 3 rotations?

Kamil Gosciminski
  • 16,547
  • 8
  • 49
  • 72

1 Answers1

0

A maximum of 3 operations(or 2 rotations) are needed when implementing a Red-Black Tree correctly. For example the central BST shown in this image will need 3 operations to make it confirm to the Red Black BST's rules.

Image to show a case when 3 operations are needed

Image taken from Robert Sedgewick's slides from this MOOC..

Nikunj Banka
  • 11,117
  • 16
  • 74
  • 112