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.

Figure 8.11: Visual justification of the l<strong>in</strong>ear runn<strong>in</strong>g<br />

time of bottom-up heap con struction, where the<br />

paths associated with the <strong>in</strong>ternal nodes have been<br />

highlighted with alternat<strong>in</strong>g colors. For example, the<br />

path associated with the root consists of the nodes<br />

stor<strong>in</strong>g keys 4, 6, 7, <strong>and</strong> 11. Also, the path associated<br />

with the right child of the root consists of the <strong>in</strong>ternal<br />

nodes stor<strong>in</strong>g keys 6, 20, <strong>and</strong> 23.<br />

To summarize, Proposition 8.7 states that the runn<strong>in</strong>g time for the first phase of<br />

heap-sort can be reduced to be O(n). Unfortunately, the runn<strong>in</strong>g time of the<br />

second phase of heap-sort cannot be made asymptotically better than O(nlogn)<br />

(that is, it will always be Ω(nlogn) <strong>in</strong> the worst case). We will not justify this<br />

lower bound until Chapter 11, however. Instead, we conclude this chapter by<br />

discuss<strong>in</strong>g a design pattern that allows us to extend the priority queue ADT to<br />

have additional functionality.<br />

8.4 Adaptable Priority Queues<br />

The methods of the priority queue ADT given <strong>in</strong> Section 8.1.3 are sufficient for most<br />

basic applications of priority queues, such as sort<strong>in</strong>g. However, there are situations<br />

where additional methods would be useful, as shown <strong>in</strong> the scenarios below, which<br />

refer to the st<strong>and</strong>by airl<strong>in</strong>e passenger application.<br />

• A st<strong>and</strong>by passenger with a pessimistic attitude may become tired of wait<strong>in</strong>g <strong>and</strong><br />

decide to leave ahead of the board<strong>in</strong>g time, request<strong>in</strong>g to be removed from the<br />

495

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

Saved successfully!

Ooh no, something went wrong!