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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Describe what additional <strong>in</strong>formation L<strong>in</strong>da's algorithm could output so that<br />

her algorithm's correctness could be established on any given S <strong>and</strong> T <strong>in</strong><br />

O(n) time.<br />

C-11.2<br />

Given two sets A <strong>and</strong> B represented as sorted sequences, describe an efficient<br />

algorithm for comput<strong>in</strong>g A > B, which is the set of elements that are <strong>in</strong> A or B,<br />

but not <strong>in</strong> both.<br />

C-11.3<br />

Suppose that we represent sets with balanced search trees. Describe <strong>and</strong> analyze<br />

algorithms for each of the methods <strong>in</strong> the set ADT, assum<strong>in</strong>g that one of the two<br />

sets is much smaller than the other.<br />

C-11.4<br />

Describe <strong>and</strong> analyze an efficient method for remov<strong>in</strong>g all duplicates from a<br />

collection A of n elements.<br />

C-11.5<br />

Consider sets whose elements are <strong>in</strong>tegers <strong>in</strong> the range [0,N − 1]. A popular<br />

scheme for represent<strong>in</strong>g a set A of this type is by means of a Boolean array, B,<br />

where we say that x is <strong>in</strong> A if <strong>and</strong> only if B[x] = true. S<strong>in</strong>ce each cell of B can be<br />

represented with a s<strong>in</strong>gle bit, B is sometimes referred to as a bit vector. Describe<br />

<strong>and</strong> analyze efficient algorithms for perform<strong>in</strong>g the methods of the set ADT<br />

assum<strong>in</strong>g this representation.<br />

C-11.6<br />

Consider a version of determ<strong>in</strong>istic quick-sort where we pick as our pivot the<br />

median of the d last elements <strong>in</strong> the <strong>in</strong>put sequence of n elements, for a fixed,<br />

constant odd number d ≥ 3. Argue <strong>in</strong>formally why this should be a good choice<br />

for pivot. What is the asymptotic worst-case runn<strong>in</strong>g time of quick-sort <strong>in</strong> this<br />

case, <strong>in</strong> terms of n <strong>and</strong> d?<br />

C-11.7<br />

Another way to analyze r<strong>and</strong>omized quick-sort is to use a recurrence equation.<br />

In this case, we let T(n) denote the expected runn<strong>in</strong>g time of r<strong>and</strong>omized quicksort,<br />

<strong>and</strong> we observe that, because of the worst-case partitions for good <strong>and</strong> bad<br />

splits, we can write<br />

T(n) ≤ 1/2 (T(3n/4) + T(n/4)) + (T(n − 1)) + bn,<br />

733

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

Saved successfully!

Ooh no, something went wrong!