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.

Case 2: The Sibl<strong>in</strong>g y of r is Black <strong>and</strong> Both Children of y are Black. (See<br />

Figures 10.33 <strong>and</strong> 10.34.) Resolv<strong>in</strong>g this case corresponds to a fusion operation <strong>in</strong><br />

the correspond<strong>in</strong>g (2,4) tree T ′. We do a recolor<strong>in</strong>g; we color r black, we color y<br />

red, <strong>and</strong>, if x is red, we color it black (Figure 10.33); otherwise, we color x double<br />

black (Figure 10.34). Hence, after this recolor<strong>in</strong>g, the double black problem may<br />

reappear at the parent x of r. (See Figure 10.34.) That is, this recolor<strong>in</strong>g either<br />

elim<strong>in</strong>ates the double black problem or propagates it <strong>in</strong>to the parent of the current<br />

node. We then repeat a consideration of these three cases at the parent. Thus,<br />

s<strong>in</strong>ce Case 1 performs a tr<strong>in</strong>ode restructur<strong>in</strong>g operation <strong>and</strong> stops (<strong>and</strong>, as we will<br />

soon see, Case 3 is similar), the number of recolor<strong>in</strong>gs caused by a removal is no<br />

more than log(n+ 1).<br />

Figure 10.33: Recolor<strong>in</strong>g of a red-black tree that<br />

fixes the double black problem: (a) before the<br />

recolor<strong>in</strong>g <strong>and</strong> correspond<strong>in</strong>g nodes <strong>in</strong> the associated<br />

(2,4) tree before the fusion (other similar<br />

configurations are possible); (b) after the recolor<strong>in</strong>g<br />

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

after the fusion.<br />

653

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

Saved successfully!

Ooh no, something went wrong!