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.

constant amount of work (<strong>in</strong> a restructur<strong>in</strong>g, recolor<strong>in</strong>g, or adjustment) per node.<br />

Thus, s<strong>in</strong>ce any changes we make at a node <strong>in</strong> T dur<strong>in</strong>g this upward march takes<br />

O(1) time (because it affects a constant number of nodes), we have the follow<strong>in</strong>g:<br />

Proposition 10.11: The algorithm for remov<strong>in</strong>g an entry from a red-black<br />

tree with n entries takes O(logn) time <strong>and</strong> performs O(logn) recolor<strong>in</strong>gs <strong>and</strong> at<br />

most one adjustment plus one additional tr<strong>in</strong>ode restructur<strong>in</strong>g. Thus, it performs at<br />

most two restructure operations.<br />

In Figures 10.36 <strong>and</strong> 10.37, we show a sequence of removal operations on a redblack<br />

tree. We illustrate Case 1 restructur<strong>in</strong>gs <strong>in</strong> Figure 10.36c <strong>and</strong> d. We<br />

illustrate Case 2 recolor<strong>in</strong>gs at several places <strong>in</strong> Figures 10.36 <strong>and</strong> 10.37. F<strong>in</strong>ally,<br />

<strong>in</strong> Figure 10.37i <strong>and</strong> j, we show an example of a Case 3 adjustment.<br />

Figure 10.36: Sequence of removals from a redblack<br />

tree: (a) <strong>in</strong>itial tree; (b) removal of 3; (c) removal<br />

of 12, caus<strong>in</strong>g a double black (h<strong>and</strong>led by<br />

restructur<strong>in</strong>g); (d) after restructur<strong>in</strong>g. (Cont<strong>in</strong>ues <strong>in</strong><br />

Figure 10.37.)<br />

Figure 10.37: Sequence of removals <strong>in</strong> a redblack<br />

tree (cont<strong>in</strong>ued): (e) removal of 17; (f) removal of<br />

657

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

Saved successfully!

Ooh no, something went wrong!