Red black tree is a binary tree having colour as an extra attribute which can be red or black.
Insertion
- Check if the tree is empty
- If the tree is empty, insert a new node as the root node having a black colour.
- If it is not empty, insert a new node on the left having a red colour.
- If the parent of new node is black then exit the operation
- If the parent of new node is red, check the color of parent node's sibling of newNode.
- If it is colored Black or NULL then make suitable Rotation and Recolor it.
- If it is colored Red then perform Recolor. Repeat the same until tree becomes Red Black Tree.
Comments
Leave a comment