BCA-2 Data Structure Using C - Tree L12 by Anant Kumar
BCA-2 Data Structure Using C - Tree L12 by Anant Kumar
USING “C”
For
ANANT KUMAR
Faculty Member
Department of Computer Science
J. D. Women’s College, Patna
Red - Black Tree
Red - Black Tree is another variant of Binary Search Tree in which every node is colored
either RED or BLACK. We can define a Red Black Tree as follows
Red Black Tree is a Binary Search Tree in which every node is colored either RED or
BLACK.
Every Red Black Tree is a binary search tree but every Binary Search Tree need not
be Red Black tree.
Recolor
Rotation
Rotation followed by Recolor
The insertion operation in Red Black tree is performed using the following steps.
Step 1 - Check whether tree is Empty.
Step 2 - If tree is Empty then insert the newNode as Root node with color Black and exit
from the operation.
Step 3 - If tree is not Empty then insert the newNode as leaf node with color Red.
Step 4 - If the parent of newNode is Black then exit from the operation.
Step 5 - If the parent of newNode is Red then check the color of parentnode's sibling of
newNode.
Step 6 - If it is colored Black or NULL then make suitable Rotation and Recolor it.
Step 7 - If it is colored Red then perform Recolor. Repeat the same until tree becomes Red
Black Tree.
Example