{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

RBtree insert-Solution

RBtree insert-Solution - 18 22 b\b b\b b\b => 8 b\r 3 14...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Solution: Indentify the nodes as follows: Z -> parent before 2 consecutive red edges is ->18 Y -> middle node between the two red edges ->22 X -> the node after the two red edges->20 18(Z) 20 / \ / \ t0 22(Y) => (a)18 22(c) / \ / \ / \ (X)20 t3 t0 t1 t2 t3 a<b<c / \ t1 t2 8 b/ \r 5 14 r/ \b b/\b 3 12 20 b/\b b/\b r/\r 18 22 b /\ b b /\ b Case 3: Two consecutive red edges. The sibling of the first red edge is red.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Insert 1: case 2 8 (c)(z) b/ \r 5 14 (b)(y)r/ \b b/ \b 3 12 20 r/\b b/\br/ \r (a)(z)1
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 18 22 b/\b b/\b b/\b => 8 b/ \r 3 14 r/ \r b/ \b 1 5 12 20 b /\ b b /\ b b /\ b b /\ b 18 22 b /\ b b /\ b Insert 19(case 3) 8 b/ \r 5 14 r/ \r b/ \b 1 5 12 20 b /\ b b /\ b b /\ b r / \ r 18 22 b /\ r b /\ b 19 b /\ b Solution: Do recoloring 1. Recolor first sibling black and also the other sibling black recolor parent edge to red This maintains the black height and breaks the double red continue fixing upwards until reaching the root....
View Full Document

{[ snackBarMessage ]}