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.

Show that the probability that any given <strong>in</strong>put element x belongs to more than<br />

2logn subproblems <strong>in</strong> size group i, for r<strong>and</strong>omized quick-sort, is at most 1/n 2 .<br />

R-11.14<br />

Suppose algorithm <strong>in</strong>PlaceQuickSort (Code Fragment 11.6) is executed on a<br />

sequence with duplicate elements. Show that the algorithm still correctly sorts<br />

the <strong>in</strong>put sequence, but the result of the divide step may differ from the highlevel<br />

description given <strong>in</strong> Section 11.2 <strong>and</strong> may result <strong>in</strong> <strong>in</strong>efficiencies. In<br />

particular, what happens <strong>in</strong> the partition step when there are elements equal to<br />

the pivot? Is the sequence E (stor<strong>in</strong>g the elements equal to the pivot) actually<br />

computed? Does the algorithm recur on the subsequences L <strong>and</strong> G, or on some<br />

other subsequences? What is the runn<strong>in</strong>g time of the algorithm if all the <strong>in</strong>put<br />

elements are equal?<br />

R-11.15<br />

Of the n# possible <strong>in</strong>puts to a given comparison-based sort<strong>in</strong>g algorithm, what is<br />

the absolute maximum number of <strong>in</strong>puts that could be sorted with just n<br />

comparisons?<br />

R-11.16<br />

Jonathan has a comparison-based sort<strong>in</strong>g algorithm that sorts the first k elements<br />

<strong>in</strong> sequence of size n <strong>in</strong> O(n) time. Give a big-Oh characterization of the biggest<br />

that k can be?<br />

R-11.17<br />

Is the merge-sort algorithm <strong>in</strong> Section 11.1 stable? Why or why not?<br />

R-11.18<br />

An algorithm that sorts key-value entries by key is said to be straggl<strong>in</strong>g if, any<br />

time two entries ei <strong>and</strong> ej have equal keys, but ei appears before ej <strong>in</strong> the <strong>in</strong>put,<br />

then the algorithm places ei after ej <strong>in</strong> the output. Describe a change to the<br />

merge-sort algorithm <strong>in</strong> Section 11.1 to make it straggl<strong>in</strong>g.<br />

R-11.19<br />

Describe a radix-sort method for lexicographically sort<strong>in</strong>g a sequence S of<br />

triplets (k,l,m), where k, l, <strong>and</strong> m are <strong>in</strong>tegers <strong>in</strong> the range [0,N − 1], for some<br />

N≥2. How could this scheme be extended to sequences of d-tuples (k 1 ,k 2 ,...,kd),<br />

where each ki is an <strong>in</strong>teger <strong>in</strong> the range [0, N − 1] ?<br />

R-11.20<br />

Is the bucket-sort algorithm <strong>in</strong>-place? Why or why not?<br />

731

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

Saved successfully!

Ooh no, something went wrong!