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.

• Take node z, its parent v, <strong>and</strong> gr<strong>and</strong>parent u, <strong>and</strong> temporarily relabel them<br />

as a, b, <strong>and</strong> c, <strong>in</strong> left-to-right order, so that a, b, <strong>and</strong> c will be visited <strong>in</strong> this<br />

order by an <strong>in</strong>order tree traversal.<br />

• Replace the gr<strong>and</strong>parent u with the node labeled b, <strong>and</strong> make nodes a <strong>and</strong><br />

c the children of b, keep<strong>in</strong>g <strong>in</strong>order relationships unchanged.<br />

After perform<strong>in</strong>g the restructure(z) operation, we color b black <strong>and</strong> we color a <strong>and</strong><br />

c red. Thus, the restructur<strong>in</strong>g elim<strong>in</strong>ates the double red problem.<br />

Figure 10.28: Restructur<strong>in</strong>g a red-black tree to<br />

remedy a double red: (a) the four configurations for u,<br />

v, <strong>and</strong> z before restructur<strong>in</strong>g; (b) after restructur<strong>in</strong>g.<br />

Case 2: The Sibl<strong>in</strong>g w of v is Red. (See Figure 10.29.) In this case, the double red<br />

denotes an overflow <strong>in</strong> the correspond<strong>in</strong>g (2,4) tree T. To fix the problem, we<br />

645

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

Saved successfully!

Ooh no, something went wrong!