• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
May 31, 2022 |12.8K Views

Red Black Tree (Insertion)

Description
Discussion

In the previous post, we discussed the introduction to Red-Black Trees. In this post, insertion is discussed. In AVL tree insertion, we used rotation as a tool to do balancing after insertion. In the Red-Black tree, we use two tools to do the balancing.

Recoloring
Rotation
Recolouring is the change in colour of the node i.e. if it is red then change it to black and vice versa. It must be noted that the colour of the NULL node is always black. Moreover, we always try recolouring first, if recolouring doesn’t work, then we go for rotation. Following is a detailed algorithm. The algorithms have mainly two cases depending upon the colour of the uncle. If the uncle is red, we do recolour. If the uncle is black, we do rotations and/or recolouring.

Red Black Tree (Insertion): https://www.geeksforgeeks.org/red-black-tree-set-2-insert/