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.

In the merge-sort tree shown <strong>in</strong> Figures 11.2 through 11.4, some edges are<br />

drawn as arrows. What is the mean<strong>in</strong>g of a downward arrow? How about an<br />

upward arrow?<br />

R-11.5<br />

Give a complete pseudo-code description of the recursive merge-sort algorithm<br />

that takes an array as its <strong>in</strong>put <strong>and</strong> output.<br />

R-11.6<br />

Show that the runn<strong>in</strong>g time of the merge-sort algorithm on an n-element<br />

sequence is O(nlogn), even when n is not a power of 2.<br />

R-11.7<br />

Suppose we are given two n-element sorted sequences A <strong>and</strong> B that should not<br />

be viewed as sets (that is, A <strong>and</strong> B may conta<strong>in</strong> duplicate entries). Describe an<br />

O(n)-time method for comput<strong>in</strong>g a sequence represent<strong>in</strong>g the set A > B (with no<br />

duplicates).<br />

R-11.8<br />

Show that (X − A) (X − B) = X − (A ∩ B), for any three sets X, A, <strong>and</strong> B.<br />

R-11.9<br />

Suppose we modify the determ<strong>in</strong>istic version of the quick-sort algorithm so that,<br />

<strong>in</strong>stead of select<strong>in</strong>g the last element <strong>in</strong> an n-element sequence as the pivot, we<br />

choose the element at <strong>in</strong>dex … ln/2…. What is the runn<strong>in</strong>g time of this version<br />

of quick-sort on a sequence that is already sorted?<br />

R-11.10<br />

Consider aga<strong>in</strong> the modification of the determ<strong>in</strong>istic version of the quicksort<br />

algorithm so that, <strong>in</strong>stead of select<strong>in</strong>g the last element <strong>in</strong> an n-element sequence<br />

as the pivot, we choose the element at <strong>in</strong>dex …ln/2…. Describe the k<strong>in</strong>d of<br />

sequence that would cause this version of quick-sort to run <strong>in</strong> (n 2 ) time.<br />

R-11.11<br />

Show that the best-case runn<strong>in</strong>g time of quick-sort on a sequence of size n with<br />

dist<strong>in</strong>ct elements is O(nlogn).<br />

R-11.12<br />

Describe a r<strong>and</strong>omized version of <strong>in</strong>-place quick-sort <strong>in</strong> pseudo-code.<br />

R-11.13<br />

730

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

Saved successfully!

Ooh no, something went wrong!