red black trees - southeast university · red black trees colored nodes definition • binary...
TRANSCRIPT
![Page 1: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/1.jpg)
Red Black Trees
Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are black. • No root-to-external-node path has two
consecutive red nodes. • All root-to-external-node paths have the
same number of black nodes
![Page 2: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/2.jpg)
Red Black Trees
Colored Edges Definition • Binary search tree. • Child pointers are colored red or black. • Pointer to an external node is black. • No root to external node path has two
consecutive red pointers. • Every root to external node path has the
same number of black pointers.
![Page 3: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/3.jpg)
Example Red-Black Tree 10
7
8
1 5
30
40
20
25
35
45
60
3
![Page 4: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/4.jpg)
Properties
• The height of a red black tree that has n (internal) nodes is between log2(n+1) and 2log2(n+1).
![Page 5: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/5.jpg)
Properties
• Start with a red black tree whose height is h; collapse all red nodes into their parent black nodes to get a tree whose node-degrees are between 2 and 4, height is >= h/2, and all external nodes are at the same level.
![Page 6: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/6.jpg)
10
7
8
1 5
30
40
20
25
35
45
60
3
Properties
![Page 7: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/7.jpg)
Properties
• Let h’>= h/2 be the height of the collapsed tree.
• Internal nodes of collapsed tree have degree between 2 and 4.
• Number of internal nodes in collapsed tree >= 2h’-1.
• So, n >= 2h’-1 • So, h <= 2 log2 (n + 1)
![Page 8: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/8.jpg)
Properties
• O(1) amortized complexity to restructure following an insert/delete.
• C++ STL implementation • java.util.TreeMap => red black tree
![Page 9: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/9.jpg)
Insert
• New pair is placed in a new node, which is inserted into the red-black tree.
• New node color options. § Black node => one root-to-external-node path has
an extra black node (black pointer). • Hard to remedy.
§ Red node => one root-to-external-node path may have two consecutive red nodes (pointers).
• May be remedied by color flips and/or a rotation.
![Page 10: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/10.jpg)
Classification Of 2 Red Nodes/Pointers
• XYz § X => relationship between gp and pp.
• pp left child of gp => X = L. § Y => relationship between pp and p.
• p left child of pp => Y = L. § z = b (black) if d = null or a black node. § z = r (red) if d is a red node.
a b
c d
gp pp
p
![Page 11: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/11.jpg)
XYr • Color flip.
a b
c d
gp pp
p
a b
c d
gp pp
p
• Move p, pp, and gp up two levels. • Continue rebalancing.
![Page 12: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/12.jpg)
LLb • Rotate.
• Done! • Same as LL rotation of AVL tree.
y
x
a b
z
c d
a b
c d
gp pp
p x
y
z
![Page 13: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/13.jpg)
LRb • Rotate.
• Done! • Same as LR rotation of AVL tree. • RRb and RLb are symmetric.
y
x
a b
z
c d
b c
a d
gp pp
p y
x
z
![Page 14: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/14.jpg)
Delete
• Delete as for unbalanced binary search tree. • If red node deleted, no rebalancing needed. • If black node deleted, a subtree becomes
one black pointer (node) deficient.
![Page 15: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/15.jpg)
Delete A Black Leaf 10
7
8
1 5
30
40
20
25
35
45
60
3
• Delete 8.
![Page 16: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/16.jpg)
Delete A Black Leaf
y
• y is root of deficient subtree.
• py is parent of y.
10
7
1 5
30
40
20
25
35
45
60
3
py
![Page 17: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/17.jpg)
Delete A Black Degree 1 Node 10
7
8
1 5
30
40
20
25
35
45
60
3
• Delete 45.
y
• y is root of deficient subtree.
py
![Page 18: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/18.jpg)
Delete A Black Degree 2 Node 10
7
8
1 5
30
40
20
25
35
45
60
3
• Not possible, degree 2 nodes are never deleted.
![Page 19: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/19.jpg)
Rebalancing Strategy • If y is a red node, make it black.
10
7
8
1 5
30
40
20
25
35
45
60
3
y
py
![Page 20: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/20.jpg)
Rebalancing Strategy • Now, no subtree is deficient. Done!
60
10
7
8
1 5
30
40
20
25
35
45 3
y
py
![Page 21: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/21.jpg)
Rebalancing Strategy • y is a black root (there is no py). • Entire tree is deficient. Done!
60
10
7
8
1 5
30
40
20
25
35
45 3
y
![Page 22: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/22.jpg)
Rebalancing Strategy • y is black but not the root (there is a py).
• Xcn § y is right child of py => X = R. § Pointer to v is black => c = b. § v has 1 red child => n = 1.
a b
y
py
v
![Page 23: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/23.jpg)
Rb0 (case 1, py is black)
• Color change. • Now, py is root of deficient subtree. • Continue!
a b
y
py
v y
a b
py
v
![Page 24: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/24.jpg)
Rb0 (case 2, py is red)
• Color change. • Deficiency eliminated. • Done!
a b
y
py
v y
a b
py
v
![Page 25: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/25.jpg)
Rb1 (case 1)
• LL rotation. • Deficiency eliminated. • Done!
a b
y
py
v a
b y
v
py
![Page 26: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/26.jpg)
Rb1 (case 2)
• LR rotation. • Deficiency eliminated. • Done!
a
y
py
v
b c
w c y
w
py
a b
v
![Page 27: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/27.jpg)
Rb2
• LR rotation. • Deficiency eliminated. • Done!
a
y
py
v
b c
w c y
w
py
a b
v
![Page 28: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/28.jpg)
Rr(n) • n = # of red children of v’s right child w.
a
y
py
v
b c
w
![Page 29: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/29.jpg)
Rr(0)
• LL rotation. • Done!
a b
y
py
v a
b y
v
py
![Page 30: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/30.jpg)
Rr(1) (case 1)
• LR rotation. • Deficiency eliminated. • Done!
a
y
py
v
b
w
c
y c
w
py
a
v
b
![Page 31: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/31.jpg)
Rr(1) (case 2)
• Rotation. • Deficiency eliminated. • Done!
a
y
py
v
b
w
c d
x
y d
x
py
a
v
b c
w
![Page 32: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/32.jpg)
Rr(2)
• Rotation. • Deficiency eliminated. • Done!
a
y
py
v
b
w
c d
x
d y
x
py
a
v
b c
w
![Page 33: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/33.jpg)
Red-Black Trees—Rank
• rank(x) = # black pointers on path from x to an external node.
• Same as #black nodes (excluding x) from x to an external node.
• rank(external node) = 0.
![Page 34: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/34.jpg)
An Example 10
7
8
1 5
30
40
20
25
35
45
60
3
0 0 0 0
0 0
0 0 0
0 0
0
0 0
1 1
1 1
1
1 1 1
2 1
2 2
3
![Page 35: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/35.jpg)
Properties Of rank(x)
• rank(x) = 0 for x an external node. • rank(x) = 1 for x parent of external node.
10
7
8
1 5
30
40
20
25
35
45
60
3
0 0 0 0
0 0
0 0 0
0 0
0
0 0
1 1
1 1
1
1 1 1
2 1
2 2
3
![Page 36: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/36.jpg)
Properties Of rank(x)
• p(x) exists => rank(x) <= rank(p(x)) <= rank(x) + 1. • g(x) exists => rank(x) < rank(g(x)).
10
7
8
1 5
30
40
20
25
35
45
60
3
0 0 0 0
0 0
0 0 0
0 0
0
0 0
1 1
1 1
1
1 1 1
2 1
2 2
3
![Page 37: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/37.jpg)
Red-Black Tree
Ø A binary search tree is a red-black tree iff integer ranks can be assigned to its nodes so as to satisfy the stated 4 properties of rank.
![Page 38: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/38.jpg)
Relationship Between rank() And Color
• (p(x),x) is a red pointer iff rank(x) = rank(p(x)). • (p(x),x) is a black pointer iff rank(x) = rank(p(x)) – 1.
10
7
8
1 5
30
40
20
25
35
45
60
3
0 0 0 0
0 0
0 0 0
0 0
0
0 0
1 1
1 1
1
1 1 1
2 1
2 2
3
![Page 39: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/39.jpg)
Relationship Between rank() And Color
• Root is black. • Other nodes:
§ Red iff pointer from parent is red. § Black iff pointer from parent is black.
![Page 40: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/40.jpg)
Relationship Between rank() And Color
• Given rank(root) and node/pointer colors, remaining ranks may be computed on way down.
10
7
8
1 5
30
40
20
25
35
45
60
3
0 0 0 0
0 0
0 0 0
0 0
0
0 0
1 1
1 1
1
1 1 1
2 1
2 2
3
![Page 41: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/41.jpg)
rank(root) & tree height
• Height <= 2 * rank(root).
10
7
8
1 5
30
40
20
25
35
45
60
3
0 0 0 0
0 0
0 0 0
0 0
0
0 0
1 1
1 1
1
1 1 1
2 1
2 2
3
![Page 42: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/42.jpg)
rank(root) & tree height
• No external nodes at levels 1, 2, …, rank(root).
10
7
8
1 5
30
40
20
25
35
45
60
3
0 0 0 0
0 0
0 0 0
0 0
0
0 0
1 1
1 1
1
1 1 1
2 1
2 2
3
![Page 43: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/43.jpg)
rank(root) & tree height
• No external nodes at levels 1, 2, …, rank(root). § So, #nodes >= Σ1 <= i <= rank(root) 2i -1 = 2 rank(root) – 1. § So, rank(root) <= log2(n+1).
• So, height(root) <= 2log2(n+1).
![Page 44: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/44.jpg)
Join(S,m,B) • Input
§ Dictionary S of pairs with small keys. § Dictionary B of pairs with big keys. § An additional pair m. § All keys in S are smaller than m.key. § All keys in B are bigger than m.key.
• Output § A dictionary that contains all pairs in S and B
plus the pair m. § Dictionaries S and B may be destroyed.
![Page 45: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/45.jpg)
Join Binary Search Trees
• O(1) time.
S
m
B
![Page 46: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/46.jpg)
Join Red-black Trees
• When rank(S) = rank(B), use binary search tree method.
S
m
B
• rank(root) = rank(S) + 1 = rank(B) + 1.
![Page 47: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/47.jpg)
rank(S) > rank(B) • Follow right child pointers from root of S to first node
x whose rank equals rank(B).
a b
x
p(x)
S
a b
x
p(x)
m
B
![Page 48: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/48.jpg)
rank(S) > rank(B) • If there are now 2 consecutive red pointers/nodes,
perform bottom-up rebalancing beginning at m. • O(rank(S) – rank(B)).
a b
x
p(x)
S
a b
x
p(x)
m
B
![Page 49: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/49.jpg)
rank(S) < rank(B)
• Follow left child pointers from root of B to first node x whose rank equals rank(S).
• Similar to case when rank(S) > rank(B).
![Page 50: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/50.jpg)
Split(k)
• Inverse of join. • Obtain
§ S … dictionary of pairs with key < k. § B … dictionary of pairs with key > k. § m … pair with key = k (if present).
![Page 51: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/51.jpg)
Split A Binary Search Tree
b
A
a B
c
C
d
D
e
E
f
m
g
S B
![Page 52: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/52.jpg)
Split A Binary Search Tree
b
A
a
B
c
C
d
D
e
E
f
m
g
B S
![Page 53: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/53.jpg)
Split A Binary Search Tree
b
A
a
B
c
C
d
D
e
E
f
m
g
B S
![Page 54: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/54.jpg)
Split A Binary Search Tree
b
A
a
B
c
C
d
D
e
E
f
m
g
B S
![Page 55: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/55.jpg)
Split A Binary Search Tree
b
A
a
B
c
C
d
D
e
E
f
m
g
B S
![Page 56: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/56.jpg)
Split A Binary Search Tree
b
A
a
B
c
C
d
D
e
E
f
m
g
B S
![Page 57: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/57.jpg)
Split A Binary Search Tree
b
A
a
B
c
C
d
D
e
E
f m
g
B S
![Page 58: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/58.jpg)
Split A Red-Black Tree
• Previous strategy does not split a red-black tree into two red-black trees.
• Must do a search for m followed by a traceback to the root.
• During the traceback use the join operation to construct S and B.
![Page 59: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/59.jpg)
Split A Red-Black Tree
b
A
a B
c
C
d
D
e
E
f
m
g
S = f B = g
![Page 60: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/60.jpg)
Split A Red-Black Tree
b
A
a B
c
C
d
D
e
E
S = f B = g
![Page 61: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/61.jpg)
Split A Red-Black Tree
b
A
a B
c
C
d
D
e
E
S = f B = g
S = join(e, E, S)
![Page 62: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/62.jpg)
Split A Red-Black Tree
b
A
a B
c
C
d
D
S = f B = g
S = join(e, E, S)
B = join(B, D, d)
![Page 63: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/63.jpg)
Split A Red-Black Tree
b
A
a B
c
C
S = f B = g
S = join(e, E, S)
B = join(B, D, d) S = join(c, C, S)
![Page 64: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/64.jpg)
Split A Red-Black Tree
b
A
a B
S = f B = g
S = join(e, E, S)
B = join(B, D, d) S = join(c, C, S) B = join(B, B, b)
![Page 65: Red Black Trees - Southeast University · Red Black Trees Colored Nodes Definition • Binary search tree. • Each node is colored red or black. • Root and all external nodes are](https://reader034.vdocument.in/reader034/viewer/2022051604/60038dada4ce62028e70d034/html5/thumbnails/65.jpg)
Split A Red-Black Tree A
a
S = f B = g
S = join(e, E, S)
B = join(B, D, d) S = join(c, C, S) B = join(B, B, b)
S = join(a, A, S)