11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Sec. 15.9 Exercises 505things by assuming th<strong>at</strong> each game takes less than an hour, <strong>and</strong> th<strong>at</strong> each teamcan be scheduled for a game every hour if necessary. (Note th<strong>at</strong> everythingsaid here about basketball courts is also true about processors in a parallelalgorithm to solve the maximum-finding problem).(a) How many basketball courts do we need to insure th<strong>at</strong> every team canplay whenever we want to minimize the total tournament time?(b) How long will the tournament be in this case?(c) Wh<strong>at</strong> is the total number of “court-hours” available? How many totalhours are courts being used? How many total court-hours are unused?(d) Modify the algorithm in such a way as to reduce the total number ofcourts needed, by perhaps not letting every team play whenever possible.This will increase the total hours of the tournament, but try to keepthe increase as low as possible. For your new algorithm, how long is thetournament, how many courts are needed, how many total court-hoursare available, how many court-hours are used, <strong>and</strong> how many unused?15.3 Explain why the cost of splitting a list of six into two lists of three to find theminimum <strong>and</strong> maximum elements requires eight comparisons, while splittingthe list into a list of two <strong>and</strong> a list of four costs only seven comparisons.15.4 Write out a table showing the number of comparisons required to find theminimum <strong>and</strong> maximum for all divisions for all values of n ≤ 13.15.5 Present an adversary argument as a lower bounds proof to show th<strong>at</strong> n − 1comparisons are necessary to find the maximum of n values in the worst case.15.6 Present an adversary argument as a lower bounds proof to show th<strong>at</strong> n comparisonsare necessary in the worst case when searching for an element withvalue X (if one exists) from among n elements.15.7 Section 15.6 claims th<strong>at</strong> by picking a pivot th<strong>at</strong> always discards <strong>at</strong> least afixed fraction c of the remaining array, the resulting algorithm will be linear.Explain why this is true. Hint: The Master Theorem (Theorem 14.1) mighthelp you.15.8 Show th<strong>at</strong> any comparison-based algorithm for finding the median must use<strong>at</strong> least n − 1 comparisons.15.9 Show th<strong>at</strong> any comparison-based algorithm for finding the second-smallestof n values can be extended to find the smallest value also, without requiringany more comparisons to be performed.15.10 Show th<strong>at</strong> any comparison-based algorithm for sorting can be modified toremove all duplic<strong>at</strong>es without requiring any more comparisons to be performed.15.11 Show th<strong>at</strong> any comparison-based algorithm for removing duplic<strong>at</strong>es from alist of values must use Ω(n log n) comparisons.15.12 Given a list of n elements, an element of the list is a majority if it appearsmore than n/2 times.

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

Saved successfully!

Ooh no, something went wrong!