23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

perform the equivalent of a split operation. Namely, we do a recolor<strong>in</strong>g: we color<br />

v <strong>and</strong> w black <strong>and</strong> their parent u red (unless u is the root, <strong>in</strong> which case, it is<br />

colored black). It is possible that, after such a recolor<strong>in</strong>g, the double red problem<br />

reappears, albeit higher up <strong>in</strong> the tree T, s<strong>in</strong>ce u may have a red parent. If the<br />

double red problem reappears at u, then we repeat the consideration of the two<br />

cases at u. Thus, a recolor<strong>in</strong>g either elim<strong>in</strong>ates the double red problem at node z,<br />

or propagates it to the gr<strong>and</strong>parent u of z. We cont<strong>in</strong>ue go<strong>in</strong>g up T perform<strong>in</strong>g<br />

recolor<strong>in</strong>gs until we f<strong>in</strong>ally resolve the double red problem (with either a f<strong>in</strong>al<br />

recolor<strong>in</strong>g or a tr<strong>in</strong>ode restructur<strong>in</strong>g). Thus, the number of recolor<strong>in</strong>gs caused by<br />

an <strong>in</strong>sertion is no more than half the height of tree T, that is, no more than log(n +<br />

1) by Proposition 10.9.<br />

Figure 10.29: Recolor<strong>in</strong>g to remedy the double<br />

red problem: (a) before recolor<strong>in</strong>g <strong>and</strong> the<br />

correspond<strong>in</strong>g 5-node <strong>in</strong> the associated (2,4) tree<br />

before the split; (b) after the recolor<strong>in</strong>g (<strong>and</strong><br />

correspond<strong>in</strong>g nodes <strong>in</strong> the associated (2,4) tree after<br />

the split).<br />

646

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!