Posts

Showing posts with the label RB trees

Insertion/Deletion in Red-Black Tree

Image
 According the property of Red-Black tree, no two Red node come together (as Parent-Child relation). So if it happens then we have to reordering the tree either by recoloring or by rotation. Note: Here NULL will considered as Black node If the uncle of the conflicting child is red:          Apply Recoloring:                    If G is root node then change it to black, also check if parent of G is red, if yes apply reordering recursively If the uncle of the conflicting child is Black:          Apply Rotation:                 Zig-Zig Rotation: This is similar to LL/RR rotation:                    Zig-Zag Rotation: This is similar to LR/RL rotation: Let us create a tree by using the following nodes:               10, 20, 30, 50, 40, ...

Red-Black Trees

Properties: It's a height balanced BST, similar to 2-3-4 Tree. Every Node is either Red or Black Root of  a tree is Black Null is also Black Number of Blacks on paths from Root to Leaf are same No 2 consecutive Red, children and parent of Red   is Black New inserted node is Red Height in logn <= h <= 2*logn (height of AVL is 1.44logn)