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.

algorithm to output the elements of S <strong>in</strong> this order, then that implies there is a way to<br />

trick the algorithm <strong>in</strong>to outputt<strong>in</strong>g xi <strong>and</strong> x j <strong>in</strong> the wrong order. S<strong>in</strong>ce this cannot be<br />

allowed by a correct sort<strong>in</strong>g algorithm, each external node of T must be associated<br />

with exactly one permutation of S. We use this property of the decision tree<br />

associated with a sort<strong>in</strong>g algorithm to prove the follow<strong>in</strong>g result:<br />

Proposition 11.4: The runn<strong>in</strong>g time of any comparison-based algorithm for<br />

sort<strong>in</strong>g an n-element sequence is Ω(nlogn)<strong>in</strong> the worst case.<br />

Justification: The runn<strong>in</strong>g time of a comparison-based sort<strong>in</strong>g algorithm must<br />

be greater than or equal to the height of the decision tree T associated with this<br />

algorithm, as described above. (See Figure 11.15.) By the argument above, each<br />

external node <strong>in</strong> T must be associated with one permutation of S. Moreover, each<br />

permutation of S must result <strong>in</strong> a different external node of T. The number of<br />

permutations of n objects is n! = n(n − 1)(n − 2) … 2 · 1. Thus, T must have at least n!<br />

external nodes. By Proposition 7.10, the height of T is at least log(n!). This<br />

immediately justifies the proposition, because there are at least n/2 terms that are<br />

greater than or equal to n/2 <strong>in</strong> the product n!; hence<br />

which is Ω(nlogn).<br />

Figure 11.15: Visualiz<strong>in</strong>g the lower bound for<br />

comparison-based sort<strong>in</strong>g.<br />

709

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

Saved successfully!

Ooh no, something went wrong!