SlideShare a Scribd company logo
Red Black Tree
Prof. Keshav Tambre
Assistant Professor
Department of Information Technology
Hope Foundation’s
International Institute of Information
Technology, I²IT
www.isquareit.edu.in
Insertion Example
Insert 65
47
7132
93
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Insertion Example
Insert 65
47
7132
65 93
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Insertion Example
Insert 65
47
7132
65 93
Insert 82
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
82
Insertion Example
Insert 65
47
7132
65 93
Insert 82
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
82
Insertion Example
Insert 65
47
7132
65 93
Insert 82
65
71
93
change nodes’ colors
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
65 93
71
82
Insertion Example
Insert 65
47
32
Insert 82
Insert 87
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
9365
71
82
Insertion Example
Insert 65
47
32
Insert 82
Insert 87
87
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
9365
71
82
Insertion Example
Insert 65
47
32
Insert 82
Insert 87
87
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
9365
71
87
Insertion ExampleInsert 65
47
32
Insert 82
Insert 87
82
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
9365
87
Insertion Example
Insert 65 47
32
Insert 82
Insert 87
82
71
87
93
change nodes’ colors
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
87
93
65
Insertion Example
Insert 65
47
32
Insert 82
Insert 87
82
71
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Left Rotation:
Modified algorithm
TreeNode<T> leftRotate(TreeNode<T> root,TreeNode<T> x)
//returns a new root; Pre: right child of x is a proper node (with value)
{
TreeNode<T> z = x.getRight();
x.setRight(z.getLeft());
// Set parent reference
if (z.getLeft() != null)
z.getLeft().setParent(x);
z.setLeft(x); //move x down
z.setParent(x.getParent());
// Set parent reference of x
if (x.getParent() != null) //x is not the root
if (x == x.getParent().getLeft()) //left child
x.getParent().setLeft(z);
else
x.getParent().setRight(z);
else
root=z;
x.setParent(z);
return root;
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
RB Tree: Insertion Algorithm
TreeNode<T> rbInsert(TreeNode<T> root,TreeNode<T> x)
// returns a new root
{
root=bstInsert(root,x); // a modification of BST insertItem
x.setColor(red);
while (x != root and x.getParent().getColor() == red) {
if (x.getParent() == x.getParent().getParent().getLeft()) {
//parent is left child
y = x.getParent().getParent().getRight() //uncle of x
if (y.getColor() == red) {// uncle is red
x.getParent().setColor(black);
y.setColor(black);
x.getParent().getParent().setColor(red);
x = x.getParent().getParent();
} else { // uncle is black
// ................
}
} else
// ... symmetric to if
} // end while
root.setColor(black);
return root;
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
x
p
left_rotateonp
right_rotate on p^2[x]
x
p
left_rotateonp
right_rotate on p^2[x]
RB Tree: Insertion AlgorithmTreeNode<T> rbInsert(TreeNode<T> root,TreeNode<T> newNode)
// returns a new root
{
root=bstInsert(root,newNode); // a modification of BST insertItem
x.setColor(red);
while (x != root and x.getParent().getColor() == red) {
if (x.getParent() == x.getParent().getParent().getLeft()) {
//parent is left
y = x.getParent().getParent().getRight() //uncle of x
if (y.getColor() == red) {// uncle is red
// ................
} else { // uncle is black
if (x == x.getParent().getRight()) {
x = x.getParent();
root = left_rotate(root,x);
}
x.getParent().setColor(black);
x.getParent().getParent().setColor(red);
root = right_rotate(root,x.getParent().getParent());
}
} else
// ... symmetric to if
} // end while
root.setColor(black);
return root;
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Red-black Tree Deletion
 First use the standard BST tree deletion algorithm
 If the node to be deleted is replaced by its
successor/predecessor (if it has two non-null children), consider
the deleted node’s data as being replaced by it’s
successor/predecessor's, and its color remaining the same
 The successor/predecessor node is then removed
 Let y be the node to be removed
 If the removed node was red, no property could get violated, so
just remove it.
 Otherwise, remove it and call the tree-fix algorithm on y’s child x
(the node which replaced the position of y)
 Remember, the removed node can have at most one real (non-null)
child
 If it has one real child, call the tree-fix algorithm on it
 If it has no real children (both children are null), Note that this child
may be a (black) pretend (null) child
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Fixing a red-black Tree
 The tree-fix algorithm considers the parameter (x)
as having an “extra” black token
 This corrects the violation of property 4 caused by
removing a black node
 If x is red, just color it black
 But if x is black then it becomes “doubly black”
 This is a violation of property 1
 The extra black token is pushed up the tree until
 a red node is reached, when it is made black
 the root node is reached or
 it can be removed by rotating and recoloring
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
87
93
65
Deletion Example 1
Delete 87
47
32
82
71
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
87
93
65
Deletion Example 1
Delete 87
47
32
82
71
Replace data with predecessor
Predecessor red: no violation
82
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
87
93
65
Deletion Example 2
Delete 71
47
32
82
71
51
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
87
93
65
Deletion Example 2
Delete 71
47
32
82
71
51
Replace with predecessor
65
Attach predecessor’s child
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
65
87
93
Deletion Example 2
Delete 71
47
32
8251
Replace with predecessor
Fix tree by coloring
predecessor’s child black
51
Attach predecessor’s child
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
87
93
65
Deletion Example 3
Delete 32
47
32
82
71
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
87
93
65
Deletion Example 3
Delete 32
47
32
82
71
x
Identify x – the removed
node’s left child
Attach x to parent of target
Remove target node
x
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
87
93
65
Deletion Example 3
Delete 32
47
82
71x
Identify x – the removed
node’s left child
Call rbTreeFix on x
Attach x to parent of target
Remove target node
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
RB Tree Deletion Algorithm
TreeNode<T> rbDelete(TreeNode<T> root,TreeNode<T> z)
//return new root, z contains item to be deleted
{
TreeNode<T> x,y;
// find node y, which is going to be removed
if (z.getLeft() == null || z.getRight() == null)
y = z;
else {
y = successor(z); // or predecessor
z.setItem(y.getItem); // move data from y to z
}
// find child x of y
if (y.getRight() != null)
x = y.getRight();
else
x = y.getLeft();
// Note x might be null; create a pretend node
if (x == null) {
x = new TreeNode<T>(null);
x.setColor(black);
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
RB Tree Deletion Algorithm
x.setParent(y.getParent()); // detach x from y
if (y.getParent() == null)
// if y was the root, x is a new root
root = x;
else
// Atttach x to y’s parent
if (y == y.getParent().getLeft()) // left child
y.getParent().setLeft(x);
else
y.getParent().setRight(x);
if (y.getColor() == black)
root=rbTreeFix(root,x);
if (x.getItem() == null) // x is a pretend node
if (x==x.getParent().getLeft())
x.getParent().setLeft(null);
else
x.getParent().setRight(null);
return root;
}
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Make y black and y’s parent
red
87
93
65
Deletion Example 3
(continued)
After deleting 32,
x is a node with
black token
47
82
71x
y
71
47
Identify y, x’s sibling
Left rotate x’s parent
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Identify y, x’s sibling
9382
71
8747
Deletion Example 3
x
y
65
new y
Identify y – x’s new sibling
Make y black and
y’s parent red
Left rotate x’s parent
After deleting 32,
x is a node with
black token
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Identify y – x’s new sibling
9382
71
8747
Deletion Example 3
x
65
y
65
new x
47
Identify y, x’s sibling
Make y black and
y’s parent red
Left rotate x’s parent
Color y red
Assign x it’s parent, and color it black
After deleting 32,
x is a node with
black token
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Tree Fix algorithm cases: case (1)
x is red
 The simplest case
 x has a black token and is colored red, so just
color it black and remove token a we are
done!
 In the remaining cases, assume x is black
(and has the black token, i.e., it’s double
black)
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Tree Fix algorithm cases: case (2)
x’s sibling is red
Remarks:
 the roots of subtrees C and D are black
 the second is the symmetric case, when x is the right child
 in the next step (case (3) or (4)) the algorithm will finish!
Left_rotate(y)
Right_rotate(y)
Colors of y and z
were swapped
Colors of x and y
were swapped
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Tree Fix algorithm cases: case (3)
x’s sibling is black and both nephews are black
Remarks:
 nephews are roots of subtrees C and D
 the black token is passed one level up
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Tree Fix algorithm cases: case (4)
x’s sibling is black and at least one nephew is red
Remarks:
 in this case, the black token is removed completely
 if the “far” nephew is black (subcase (i)), rotate its parent, so that
a new “far” nephew is red; otherwise start in subcase(ii)
Left_rotate(x)
Left_rotate(y)Right_rotate(w)
Right_rotate(z)
Colors of z and w
were swapped
Colors of x and y
were swapped
Colors of y and z
were swapped.
Far nephew is
colored black and
black token is removed.
Colors of z and y
were swapped.
Far nephew is
colored black and
black token is removed.
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Left_rotate(y)
Right_rotate(y)
Colors of y and z
were swapped
Colors of x and y
were swapped
Left_rotate(y)
Right_rotate(y)
Colors of y and z
were swapped
Colors of x and y
were swapped
Left_rotate(y)
Right_rotate(y)
Colors of y and z
were swapped
Colors of x and y
were swapped
Tree Fix Algorithm
TreeNode<T> rbTreeFix(TreeNode<T> root,TreeNode<T> x)
//return new root; x is a node with the black token
{
while (x != root && x.getColor() == black) // not case (1)
if (x == x.getParent().getLeft()) { // x is left child
y = x.getParent().getRight(); // y is x’s sibling
if (y.getColor() == red) { // case (2)
y.setColor(black);
x.getParent().setColor(red); // p was black
root = left_rotate(root,x.getParent());
y = x.getParent().getRight(); // new sibling
}
if (y.getLeft().getColor() == black &&
y.getRight().getColor() == black) {
// nephews are black - case (3)
y.setColor(red);
x = x.getParent();
} else { // case (4)
// ..........
}
} else {
… // x is right child - symmetric
}
// end while loop
x.setColor(black);
return root;
} Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
Tree Fix Algorithm (continued)
} else { // case (4)
if (y.getRight().getColor() == black) {
// subcase (i)
y.getLeft().setColor(black);
y.setColor(red);
root = right_rotate(root,y);
y = x.getParent().getRight();
}
// subcase (ii)
y.setColor(x.getParent().getColor());
x.getParent().setColor(black);
y.getRight().setColor(black);
root = left_rotate(root, x.getParent());
x = root; // we can finish
}
Left_rotate(x)
Left_rotate(y)Right_rotate(w)
Right_rotate(z)
Colors of z and w
were swapped
Colors of z and y
were swapped.
Left_rotate(x)
Left_rotate(y)Right_rotate(w)
Right_rotate(z)
Colors of z and w
were swapped
Colors of z and y
were swapped.
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
RB Trees efficiency
 All operations work in time O(height)
 and we have proved that heigh is O(log n)
 hence, all operations work in time O(log n)! – much more
efficient than linked list or arrays implementation of sorted list!
Sorted List Search Insertion Deletion
with arrays O(log n) O(n) O(n)
with linked list O(n) O(n) O(n)
with RB trees O(log n) O(log n) O(log n)
Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
THANK YOU
For further details, please contact
Keshav Tambre
keshavt@isquareit.edu.in
Department of Information Technology
Hope Foundation’s
International Institute of Information Technology, I²IT
P-14,Rajiv Gandhi Infotech Park
MIDC Phase 1, Hinjawadi, Pune – 411057
Tel - +91 20 22933441/2/3
www.isquareit.edu.in | info@isquareit.edu.in

More Related Content

What's hot

1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Krish_ver2
 
Fp growth
Fp growthFp growth
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...
Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...
Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...
Edureka!
 
Data Mining: Association Rules Basics
Data Mining: Association Rules BasicsData Mining: Association Rules Basics
Data Mining: Association Rules Basics
Benazir Income Support Program (BISP)
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
DrkhanchanaR
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentationAlizay Khan
 
Unit 3 graph chapter6
Unit 3  graph chapter6Unit 3  graph chapter6
Unit 3 graph chapter6
DrkhanchanaR
 
Heap and heapsort
Heap and heapsortHeap and heapsort
Heap and heapsort
Amit Kumar Rathi
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
almario1988
 
Quick sort
Quick sortQuick sort
Red black tree
Red black treeRed black tree
Red black tree
Rajendran
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
MdSajjadulislamBappi
 
Graph data structure and algorithms
Graph data structure and algorithmsGraph data structure and algorithms
Graph data structure and algorithms
Anandhasilambarasan D
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
Shareb Ismaeel
 
BFS
BFSBFS
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
hamza javed
 

What's hot (20)

1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Fp growth
Fp growthFp growth
Fp growth
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...
Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...
Decision Tree Algorithm | Decision Tree in Python | Machine Learning Algorith...
 
Data Mining: Association Rules Basics
Data Mining: Association Rules BasicsData Mining: Association Rules Basics
Data Mining: Association Rules Basics
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Unit 3 graph chapter6
Unit 3  graph chapter6Unit 3  graph chapter6
Unit 3 graph chapter6
 
Heap and heapsort
Heap and heapsortHeap and heapsort
Heap and heapsort
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 
Quick sort
Quick sortQuick sort
Quick sort
 
Red black tree
Red black treeRed black tree
Red black tree
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Graph data structure and algorithms
Graph data structure and algorithmsGraph data structure and algorithms
Graph data structure and algorithms
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
BFS
BFSBFS
BFS
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 

Similar to Red Black Tree Insertion & Deletion

NP-Complete Problem
NP-Complete Problem NP-Complete Problem
Engineering Mathematics & Probability Distributions
Engineering Mathematics & Probability DistributionsEngineering Mathematics & Probability Distributions
Engineering Mathematics & Probability Distributions
International Institute of Information Technology (I²IT)
 
Red Black Tree (and Examples)
Red Black Tree (and Examples)Red Black Tree (and Examples)
Basics of Digital Electronics
Basics of Digital ElectronicsBasics of Digital Electronics
Euler’s Theorem Homogeneous Function Of Two Variables
Euler’s Theorem Homogeneous Function Of  Two VariablesEuler’s Theorem Homogeneous Function Of  Two Variables
Euler’s Theorem Homogeneous Function Of Two Variables
International Institute of Information Technology (I²IT)
 
Differential Equation - Order Degree
Differential Equation - Order DegreeDifferential Equation - Order Degree
Differential Equation - Order Degree
International Institute of Information Technology (I²IT)
 
Factor Analysis & The Measurement Model
Factor Analysis & The Measurement Model Factor Analysis & The Measurement Model
Factor Analysis & The Measurement Model
International Institute of Information Technology (I²IT)
 
Design Procedure for an Integrator
Design Procedure for an IntegratorDesign Procedure for an Integrator
AVL Tree Explained
AVL Tree ExplainedAVL Tree Explained
Conformal Mapping - Introduction & Examples
Conformal Mapping - Introduction & ExamplesConformal Mapping - Introduction & Examples
Conformal Mapping - Introduction & Examples
International Institute of Information Technology (I²IT)
 
Engineering Mathematics | Maxima and Minima
Engineering Mathematics | Maxima and MinimaEngineering Mathematics | Maxima and Minima
Engineering Mathematics | Maxima and Minima
International Institute of Information Technology (I²IT)
 
Engineering Mathematics with Examples and Applications
Engineering Mathematics with Examples and ApplicationsEngineering Mathematics with Examples and Applications
Engineering Mathematics with Examples and Applications
International Institute of Information Technology (I²IT)
 
Adapter Pattern: Introduction & Implementation (with examples)
Adapter Pattern: Introduction & Implementation (with examples)Adapter Pattern: Introduction & Implementation (with examples)
Adapter Pattern: Introduction & Implementation (with examples)
International Institute of Information Technology (I²IT)
 
Importance of Theory of Computations
Importance of Theory of ComputationsImportance of Theory of Computations
Importance of Theory of Computations
International Institute of Information Technology (I²IT)
 
FUSION - Pattern Recognition, Classification, Classifier Fusion
FUSION - Pattern Recognition, Classification, Classifier Fusion FUSION - Pattern Recognition, Classification, Classifier Fusion
FUSION - Pattern Recognition, Classification, Classifier Fusion
International Institute of Information Technology (I²IT)
 
Strings in Python
Strings in PythonStrings in Python
Systems Programming & Operating Systems - Overview of LEX-and-YACC
Systems Programming & Operating Systems - Overview of LEX-and-YACCSystems Programming & Operating Systems - Overview of LEX-and-YACC
Systems Programming & Operating Systems - Overview of LEX-and-YACC
International Institute of Information Technology (I²IT)
 
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
International Institute of Information Technology (I²IT)
 
Newton's Laws of Motion
Newton's Laws of MotionNewton's Laws of Motion
Types of Artificial Intelligence
Types of Artificial Intelligence Types of Artificial Intelligence

Similar to Red Black Tree Insertion & Deletion (20)

NP-Complete Problem
NP-Complete Problem NP-Complete Problem
NP-Complete Problem
 
Engineering Mathematics & Probability Distributions
Engineering Mathematics & Probability DistributionsEngineering Mathematics & Probability Distributions
Engineering Mathematics & Probability Distributions
 
Red Black Tree (and Examples)
Red Black Tree (and Examples)Red Black Tree (and Examples)
Red Black Tree (and Examples)
 
Basics of Digital Electronics
Basics of Digital ElectronicsBasics of Digital Electronics
Basics of Digital Electronics
 
Euler’s Theorem Homogeneous Function Of Two Variables
Euler’s Theorem Homogeneous Function Of  Two VariablesEuler’s Theorem Homogeneous Function Of  Two Variables
Euler’s Theorem Homogeneous Function Of Two Variables
 
Differential Equation - Order Degree
Differential Equation - Order DegreeDifferential Equation - Order Degree
Differential Equation - Order Degree
 
Factor Analysis & The Measurement Model
Factor Analysis & The Measurement Model Factor Analysis & The Measurement Model
Factor Analysis & The Measurement Model
 
Design Procedure for an Integrator
Design Procedure for an IntegratorDesign Procedure for an Integrator
Design Procedure for an Integrator
 
AVL Tree Explained
AVL Tree ExplainedAVL Tree Explained
AVL Tree Explained
 
Conformal Mapping - Introduction & Examples
Conformal Mapping - Introduction & ExamplesConformal Mapping - Introduction & Examples
Conformal Mapping - Introduction & Examples
 
Engineering Mathematics | Maxima and Minima
Engineering Mathematics | Maxima and MinimaEngineering Mathematics | Maxima and Minima
Engineering Mathematics | Maxima and Minima
 
Engineering Mathematics with Examples and Applications
Engineering Mathematics with Examples and ApplicationsEngineering Mathematics with Examples and Applications
Engineering Mathematics with Examples and Applications
 
Adapter Pattern: Introduction & Implementation (with examples)
Adapter Pattern: Introduction & Implementation (with examples)Adapter Pattern: Introduction & Implementation (with examples)
Adapter Pattern: Introduction & Implementation (with examples)
 
Importance of Theory of Computations
Importance of Theory of ComputationsImportance of Theory of Computations
Importance of Theory of Computations
 
FUSION - Pattern Recognition, Classification, Classifier Fusion
FUSION - Pattern Recognition, Classification, Classifier Fusion FUSION - Pattern Recognition, Classification, Classifier Fusion
FUSION - Pattern Recognition, Classification, Classifier Fusion
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Systems Programming & Operating Systems - Overview of LEX-and-YACC
Systems Programming & Operating Systems - Overview of LEX-and-YACCSystems Programming & Operating Systems - Overview of LEX-and-YACC
Systems Programming & Operating Systems - Overview of LEX-and-YACC
 
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
 
Newton's Laws of Motion
Newton's Laws of MotionNewton's Laws of Motion
Newton's Laws of Motion
 
Types of Artificial Intelligence
Types of Artificial Intelligence Types of Artificial Intelligence
Types of Artificial Intelligence
 

More from International Institute of Information Technology (I²IT)

Minimization of DFA
Minimization of DFAMinimization of DFA
Understanding Natural Language Processing
Understanding Natural Language ProcessingUnderstanding Natural Language Processing
Understanding Natural Language Processing
International Institute of Information Technology (I²IT)
 
What Is Smart Computing?
What Is Smart Computing?What Is Smart Computing?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
International Institute of Information Technology (I²IT)
 
Writing Skills: Importance of Writing Skills
Writing Skills: Importance of Writing SkillsWriting Skills: Importance of Writing Skills
Writing Skills: Importance of Writing Skills
International Institute of Information Technology (I²IT)
 
Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself
International Institute of Information Technology (I²IT)
 
Servlet: A Server-side Technology
Servlet: A Server-side TechnologyServlet: A Server-side Technology
What Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It WorksWhat Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It Works
International Institute of Information Technology (I²IT)
 
Cloud Computing
Cloud ComputingCloud Computing
Hypothesis-Testing
Hypothesis-TestingHypothesis-Testing
Data Science, Big Data, Data Analytics
Data Science, Big Data, Data AnalyticsData Science, Big Data, Data Analytics
Data Science, Big Data, Data Analytics
International Institute of Information Technology (I²IT)
 
Sentiment Analysis in Machine Learning
Sentiment Analysis in  Machine LearningSentiment Analysis in  Machine Learning
Sentiment Analysis in Machine Learning
International Institute of Information Technology (I²IT)
 
What Is Cloud Computing?
What Is Cloud Computing?What Is Cloud Computing?
Introduction To Design Pattern
Introduction To Design PatternIntroduction To Design Pattern
Java as Object Oriented Programming Language
Java as Object Oriented Programming LanguageJava as Object Oriented Programming Language
Java as Object Oriented Programming Language
International Institute of Information Technology (I²IT)
 
What Is High Performance-Computing?
What Is High Performance-Computing?What Is High Performance-Computing?
Data Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BIData Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BI
International Institute of Information Technology (I²IT)
 
Yoga To Fight & Win Against COVID-19
Yoga To Fight & Win Against COVID-19Yoga To Fight & Win Against COVID-19
Yoga To Fight & Win Against COVID-19
International Institute of Information Technology (I²IT)
 
LR(0) PARSER
LR(0) PARSERLR(0) PARSER
Programming with LEX & YACC
Programming with LEX & YACCProgramming with LEX & YACC

More from International Institute of Information Technology (I²IT) (20)

Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Understanding Natural Language Processing
Understanding Natural Language ProcessingUnderstanding Natural Language Processing
Understanding Natural Language Processing
 
What Is Smart Computing?
What Is Smart Computing?What Is Smart Computing?
What Is Smart Computing?
 
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
 
Writing Skills: Importance of Writing Skills
Writing Skills: Importance of Writing SkillsWriting Skills: Importance of Writing Skills
Writing Skills: Importance of Writing Skills
 
Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself
 
Servlet: A Server-side Technology
Servlet: A Server-side TechnologyServlet: A Server-side Technology
Servlet: A Server-side Technology
 
What Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It WorksWhat Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It Works
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
Hypothesis-Testing
Hypothesis-TestingHypothesis-Testing
Hypothesis-Testing
 
Data Science, Big Data, Data Analytics
Data Science, Big Data, Data AnalyticsData Science, Big Data, Data Analytics
Data Science, Big Data, Data Analytics
 
Sentiment Analysis in Machine Learning
Sentiment Analysis in  Machine LearningSentiment Analysis in  Machine Learning
Sentiment Analysis in Machine Learning
 
What Is Cloud Computing?
What Is Cloud Computing?What Is Cloud Computing?
What Is Cloud Computing?
 
Introduction To Design Pattern
Introduction To Design PatternIntroduction To Design Pattern
Introduction To Design Pattern
 
Java as Object Oriented Programming Language
Java as Object Oriented Programming LanguageJava as Object Oriented Programming Language
Java as Object Oriented Programming Language
 
What Is High Performance-Computing?
What Is High Performance-Computing?What Is High Performance-Computing?
What Is High Performance-Computing?
 
Data Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BIData Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BI
 
Yoga To Fight & Win Against COVID-19
Yoga To Fight & Win Against COVID-19Yoga To Fight & Win Against COVID-19
Yoga To Fight & Win Against COVID-19
 
LR(0) PARSER
LR(0) PARSERLR(0) PARSER
LR(0) PARSER
 
Programming with LEX & YACC
Programming with LEX & YACCProgramming with LEX & YACC
Programming with LEX & YACC
 

Recently uploaded

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 

Recently uploaded (20)

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 

Red Black Tree Insertion & Deletion

  • 1. Red Black Tree Prof. Keshav Tambre Assistant Professor Department of Information Technology Hope Foundation’s International Institute of Information Technology, I²IT www.isquareit.edu.in
  • 2. Insertion Example Insert 65 47 7132 93 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 3. Insertion Example Insert 65 47 7132 65 93 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 4. Insertion Example Insert 65 47 7132 65 93 Insert 82 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 5. 82 Insertion Example Insert 65 47 7132 65 93 Insert 82 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 6. 82 Insertion Example Insert 65 47 7132 65 93 Insert 82 65 71 93 change nodes’ colors Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 7. 65 93 71 82 Insertion Example Insert 65 47 32 Insert 82 Insert 87 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 8. 9365 71 82 Insertion Example Insert 65 47 32 Insert 82 Insert 87 87 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 9. 9365 71 82 Insertion Example Insert 65 47 32 Insert 82 Insert 87 87 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 10. 9365 71 87 Insertion ExampleInsert 65 47 32 Insert 82 Insert 87 82 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 11. 9365 87 Insertion Example Insert 65 47 32 Insert 82 Insert 87 82 71 87 93 change nodes’ colors Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 12. 87 93 65 Insertion Example Insert 65 47 32 Insert 82 Insert 87 82 71 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 13. Left Rotation: Modified algorithm TreeNode<T> leftRotate(TreeNode<T> root,TreeNode<T> x) //returns a new root; Pre: right child of x is a proper node (with value) { TreeNode<T> z = x.getRight(); x.setRight(z.getLeft()); // Set parent reference if (z.getLeft() != null) z.getLeft().setParent(x); z.setLeft(x); //move x down z.setParent(x.getParent()); // Set parent reference of x if (x.getParent() != null) //x is not the root if (x == x.getParent().getLeft()) //left child x.getParent().setLeft(z); else x.getParent().setRight(z); else root=z; x.setParent(z); return root; } Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 14. RB Tree: Insertion Algorithm TreeNode<T> rbInsert(TreeNode<T> root,TreeNode<T> x) // returns a new root { root=bstInsert(root,x); // a modification of BST insertItem x.setColor(red); while (x != root and x.getParent().getColor() == red) { if (x.getParent() == x.getParent().getParent().getLeft()) { //parent is left child y = x.getParent().getParent().getRight() //uncle of x if (y.getColor() == red) {// uncle is red x.getParent().setColor(black); y.setColor(black); x.getParent().getParent().setColor(red); x = x.getParent().getParent(); } else { // uncle is black // ................ } } else // ... symmetric to if } // end while root.setColor(black); return root; } Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 15. x p left_rotateonp right_rotate on p^2[x] x p left_rotateonp right_rotate on p^2[x] RB Tree: Insertion AlgorithmTreeNode<T> rbInsert(TreeNode<T> root,TreeNode<T> newNode) // returns a new root { root=bstInsert(root,newNode); // a modification of BST insertItem x.setColor(red); while (x != root and x.getParent().getColor() == red) { if (x.getParent() == x.getParent().getParent().getLeft()) { //parent is left y = x.getParent().getParent().getRight() //uncle of x if (y.getColor() == red) {// uncle is red // ................ } else { // uncle is black if (x == x.getParent().getRight()) { x = x.getParent(); root = left_rotate(root,x); } x.getParent().setColor(black); x.getParent().getParent().setColor(red); root = right_rotate(root,x.getParent().getParent()); } } else // ... symmetric to if } // end while root.setColor(black); return root; } Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 16. Red-black Tree Deletion  First use the standard BST tree deletion algorithm  If the node to be deleted is replaced by its successor/predecessor (if it has two non-null children), consider the deleted node’s data as being replaced by it’s successor/predecessor's, and its color remaining the same  The successor/predecessor node is then removed  Let y be the node to be removed  If the removed node was red, no property could get violated, so just remove it.  Otherwise, remove it and call the tree-fix algorithm on y’s child x (the node which replaced the position of y)  Remember, the removed node can have at most one real (non-null) child  If it has one real child, call the tree-fix algorithm on it  If it has no real children (both children are null), Note that this child may be a (black) pretend (null) child Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 17. Fixing a red-black Tree  The tree-fix algorithm considers the parameter (x) as having an “extra” black token  This corrects the violation of property 4 caused by removing a black node  If x is red, just color it black  But if x is black then it becomes “doubly black”  This is a violation of property 1  The extra black token is pushed up the tree until  a red node is reached, when it is made black  the root node is reached or  it can be removed by rotating and recoloring Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 18. 87 93 65 Deletion Example 1 Delete 87 47 32 82 71 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 19. 87 93 65 Deletion Example 1 Delete 87 47 32 82 71 Replace data with predecessor Predecessor red: no violation 82 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 20. 87 93 65 Deletion Example 2 Delete 71 47 32 82 71 51 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 21. 87 93 65 Deletion Example 2 Delete 71 47 32 82 71 51 Replace with predecessor 65 Attach predecessor’s child Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 22. 65 87 93 Deletion Example 2 Delete 71 47 32 8251 Replace with predecessor Fix tree by coloring predecessor’s child black 51 Attach predecessor’s child Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 23. 87 93 65 Deletion Example 3 Delete 32 47 32 82 71 Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 24. 87 93 65 Deletion Example 3 Delete 32 47 32 82 71 x Identify x – the removed node’s left child Attach x to parent of target Remove target node x Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 25. 87 93 65 Deletion Example 3 Delete 32 47 82 71x Identify x – the removed node’s left child Call rbTreeFix on x Attach x to parent of target Remove target node Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 26. RB Tree Deletion Algorithm TreeNode<T> rbDelete(TreeNode<T> root,TreeNode<T> z) //return new root, z contains item to be deleted { TreeNode<T> x,y; // find node y, which is going to be removed if (z.getLeft() == null || z.getRight() == null) y = z; else { y = successor(z); // or predecessor z.setItem(y.getItem); // move data from y to z } // find child x of y if (y.getRight() != null) x = y.getRight(); else x = y.getLeft(); // Note x might be null; create a pretend node if (x == null) { x = new TreeNode<T>(null); x.setColor(black); } Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 27. RB Tree Deletion Algorithm x.setParent(y.getParent()); // detach x from y if (y.getParent() == null) // if y was the root, x is a new root root = x; else // Atttach x to y’s parent if (y == y.getParent().getLeft()) // left child y.getParent().setLeft(x); else y.getParent().setRight(x); if (y.getColor() == black) root=rbTreeFix(root,x); if (x.getItem() == null) // x is a pretend node if (x==x.getParent().getLeft()) x.getParent().setLeft(null); else x.getParent().setRight(null); return root; } Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 28. Make y black and y’s parent red 87 93 65 Deletion Example 3 (continued) After deleting 32, x is a node with black token 47 82 71x y 71 47 Identify y, x’s sibling Left rotate x’s parent Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 29. Identify y, x’s sibling 9382 71 8747 Deletion Example 3 x y 65 new y Identify y – x’s new sibling Make y black and y’s parent red Left rotate x’s parent After deleting 32, x is a node with black token Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 30. Identify y – x’s new sibling 9382 71 8747 Deletion Example 3 x 65 y 65 new x 47 Identify y, x’s sibling Make y black and y’s parent red Left rotate x’s parent Color y red Assign x it’s parent, and color it black After deleting 32, x is a node with black token Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 31. Tree Fix algorithm cases: case (1) x is red  The simplest case  x has a black token and is colored red, so just color it black and remove token a we are done!  In the remaining cases, assume x is black (and has the black token, i.e., it’s double black) Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 32. Tree Fix algorithm cases: case (2) x’s sibling is red Remarks:  the roots of subtrees C and D are black  the second is the symmetric case, when x is the right child  in the next step (case (3) or (4)) the algorithm will finish! Left_rotate(y) Right_rotate(y) Colors of y and z were swapped Colors of x and y were swapped Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 33. Tree Fix algorithm cases: case (3) x’s sibling is black and both nephews are black Remarks:  nephews are roots of subtrees C and D  the black token is passed one level up Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 34. Tree Fix algorithm cases: case (4) x’s sibling is black and at least one nephew is red Remarks:  in this case, the black token is removed completely  if the “far” nephew is black (subcase (i)), rotate its parent, so that a new “far” nephew is red; otherwise start in subcase(ii) Left_rotate(x) Left_rotate(y)Right_rotate(w) Right_rotate(z) Colors of z and w were swapped Colors of x and y were swapped Colors of y and z were swapped. Far nephew is colored black and black token is removed. Colors of z and y were swapped. Far nephew is colored black and black token is removed. Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 35. Left_rotate(y) Right_rotate(y) Colors of y and z were swapped Colors of x and y were swapped Left_rotate(y) Right_rotate(y) Colors of y and z were swapped Colors of x and y were swapped Left_rotate(y) Right_rotate(y) Colors of y and z were swapped Colors of x and y were swapped Tree Fix Algorithm TreeNode<T> rbTreeFix(TreeNode<T> root,TreeNode<T> x) //return new root; x is a node with the black token { while (x != root && x.getColor() == black) // not case (1) if (x == x.getParent().getLeft()) { // x is left child y = x.getParent().getRight(); // y is x’s sibling if (y.getColor() == red) { // case (2) y.setColor(black); x.getParent().setColor(red); // p was black root = left_rotate(root,x.getParent()); y = x.getParent().getRight(); // new sibling } if (y.getLeft().getColor() == black && y.getRight().getColor() == black) { // nephews are black - case (3) y.setColor(red); x = x.getParent(); } else { // case (4) // .......... } } else { … // x is right child - symmetric } // end while loop x.setColor(black); return root; } Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 36. Tree Fix Algorithm (continued) } else { // case (4) if (y.getRight().getColor() == black) { // subcase (i) y.getLeft().setColor(black); y.setColor(red); root = right_rotate(root,y); y = x.getParent().getRight(); } // subcase (ii) y.setColor(x.getParent().getColor()); x.getParent().setColor(black); y.getRight().setColor(black); root = left_rotate(root, x.getParent()); x = root; // we can finish } Left_rotate(x) Left_rotate(y)Right_rotate(w) Right_rotate(z) Colors of z and w were swapped Colors of z and y were swapped. Left_rotate(x) Left_rotate(y)Right_rotate(w) Right_rotate(z) Colors of z and w were swapped Colors of z and y were swapped. Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 37. RB Trees efficiency  All operations work in time O(height)  and we have proved that heigh is O(log n)  hence, all operations work in time O(log n)! – much more efficient than linked list or arrays implementation of sorted list! Sorted List Search Insertion Deletion with arrays O(log n) O(n) O(n) with linked list O(n) O(n) O(n) with RB trees O(log n) O(log n) O(log n) Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 | www.isquareit.edu.in | info@isquareit.edu.in
  • 38. THANK YOU For further details, please contact Keshav Tambre keshavt@isquareit.edu.in Department of Information Technology Hope Foundation’s International Institute of Information Technology, I²IT P-14,Rajiv Gandhi Infotech Park MIDC Phase 1, Hinjawadi, Pune – 411057 Tel - +91 20 22933441/2/3 www.isquareit.edu.in | info@isquareit.edu.in