Data Structures &
Algorithms
Subodh Kumar([email protected], Bharti 422)
Dept of Computer Sc. & Engg.
Binar-izing a 2-4 Tree
!71
Binar-izing a 2-4 Tree
!71
10 15
Binar-izing a 2-4 Tree
!71
10 15
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
10 1510
15
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
10 1510
15 10
15
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
10 15
21 28 49
10
15 10
15
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
lg3n = .63 lg2n
Binar-izing a 2-4 Tree
!71
28
4921
10 15
21 28 49
10
15 10
15
10
Red Black Tree
lg3n = .63 lg2n
Red Black Tree! No red colored node has a red colored child! The number of black colored node on the
path from the root to each null reference is the same
!72
Red Black Tree! No red colored node has a red colored child! The number of black colored node on the
path from the root to each null reference is the same
!72
=> height ≤ 2 log (n)
Red Black Tree! No red colored node has a red colored child! The number of black colored node on the
path from the root to each null reference is the same
!72
=> height ≤ 2 log (n)
• Null references are assumed black• Root is always black
Binar-ized 2-4 Tree
!73
10 15
21 28 49
30 50251 4 7 11 1214 20
2 5 13
Binar-ized 2-4 Tree
!73
10
15
21 28 49
30 50251 4 7 11 1214 20
2 5 13
Binar-ized 2-4 Tree
!73
10
15
2
521 28 49
30 50251 4 7 11 1214 20
13
Binar-ized 2-4 Tree
!73
10
15
2
513 21 28 49
30 50251 4 7 11 1214 20
Binar-ized 2-4 Tree
!73
10
15
2
513 21
28
49
30 50251 4 7 11 1214 20
Binar-ized 2-4 Tree
!73
10
15
2
513 21
28
49
1 4 7
11
1214 20 25 5030
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
Insert
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
Insert 24
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
24
Insert 24
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
24
Insert 24Insert 22
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
24
22
Insert 24Insert 22
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
24
22
Insert 24Insert 22
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
24
22
Insert 24Insert 22
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20 25 5030
24
22
Insert 24Insert 22
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
Insert 24Insert 22
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
Insert 24Insert 22
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
Insert 24Insert 22Insert 23
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
49
Red-Black Tree Insert
!74
10
15
2
5
1 4 7
13
12
11
14
21
28
20
25
503024
22
23
Insert 24Insert 22Insert 23
Insert @null in node n
Red uncle
Color new node RedBlack parent ⇒ DoneRed parent ⇒ Black Uncle: Restructure
Red Uncle: Recolor + Recur up
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child.
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child.
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child.
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child.
R-B Tree Deletion
!75
10
15
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child. Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20 25 5030
Delete 10
24
Expunge node n with @null in child.
Delete 20
Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20
25 5030
Delete 10
24
Expunge node n with @null in child.
Delete 20
Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20
25 5030
Delete 10
24
Expunge node n with @null in child.
Delete 20
Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20
25 5030
Delete 10
24
Expunge node n with @null in child.
Delete 20
Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20
25 5030
Delete 10
24
Expunge node n with @null in child.
Delete 20
Simple if n is red.Also simple if n ’s child is red.
R-B Tree Deletion
!75
1015
5
2
1 4 7
13
12
11
14
21 49
28
20
25 5030
Delete 10
24
Expunge node n with @null in child.
Delete 20
Simple if n is red.Also simple if n ’s child is red.
Complex Delete Cases
!76
Complex Delete Cases
!76
Complex Delete Cases
!76
P
d
d-1
Complex Delete Cases
!76
S
P
d
d-1d
S
Complex Delete Cases
!76
S
P P
d
d-1d
d
d-1
S
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d-1
S
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d-1
S
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d-1
S
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d-1
Count +1
S
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d-1
Count +1
S
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d-1
S
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d
d-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d
d
d -1
-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d
d
d -1
-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d
d
d
-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d
d
d
-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
n2n1
d
d-1
d
d
-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1-1
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
S
P
d
d
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1-1
S
P
d
d
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
ns
-1
S
P
d
d
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
ns
n1 n2
-1
S
P
d
d
S
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
ns
n1 n2
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
ns
n1 n2
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
ns
n1 n2
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
ns
n1 n2
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
d-1ns
n1 n2
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
d-1ns
n1 n2
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
d-1ns
n1 n2 d
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
d-1ns
n1 n2 d d
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
d-1ns
n1 n2 d d
-1
S
P
d
d
S
n1
SP
n2
S
P
n1
n2
Complex Delete Cases
!76
S
P P
d
d-1
n1 n2d d
d
d
d
d-1
d
d
S
P
d
n2n1
d-1
d-1ns
n1 n2 d d
-1
if color == Red: "if singlechild().color == Red: singlechild.setcolor(black) "putblack();
putblack(): if root(): " if color == Red: setcolor(Black) " s = sibling(); if s.color == Red: Restructure s.child; s.swapcolor(); # if nephew() == !Red: // i.e., null or Black sibling().setcolor(Red); parent.putblack(); else: Restructure sibling.child() "
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20 25 5030
Expunge node with @null in node n
24
Delete 20
26
21
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25 5030
Expunge node with @null in node n
24
Delete 20
26
21
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25 5030
Expunge node with @null in node n
24
Delete 20
26
21d = 3
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25 5030
Expunge node with @null in node n
24
Delete 20
26
21d = 3
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25 5030
Expunge node with @null in node n
24
Delete 20
26
21d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25 5030
Expunge node with @null in node n
24
Delete 20
26
21d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
Black Sibling ⇒ No red nephew: Recolor S,P; Fix P. Red nephew: Restructure P,S,n; Done.
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
Black Sibling ⇒ No red nephew: Recolor S,P; Fix P. Red nephew: Restructure P,S,n; Done.
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
Black Sibling ⇒ No red nephew: Recolor S,P; Fix P. Red nephew: Restructure P,S,n; Done.
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
Black Sibling ⇒ No red nephew: Recolor S,P; Fix P. Red nephew: Restructure P,S,n; Done.
49
Red-Black Tree
!77
10
15
2
5
1 4 7
13
12
11
14
28
20
25
5030
Expunge node with @null in node n
24
Delete 20
2621
d = 3
Red Sibling ⇒ Restructure P,S,n
P←Red; S←Black
Black Sibling ⇒ No red nephew: Recolor S,P; Fix P. Red nephew: Restructure P,S,n; Done.