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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

506 Chap. 15 Lower Bounds(a) Assume th<strong>at</strong> the input is a list of integers. Design an algorithm th<strong>at</strong> islinear in the number of integer-integer comparisons in the worst caseth<strong>at</strong> will find <strong>and</strong> report the majority if one exists, <strong>and</strong> report th<strong>at</strong> thereis no majority if no such integer exists in the list.(b) Assume th<strong>at</strong> the input is a list of elements th<strong>at</strong> have no rel<strong>at</strong>ive ordering,such as colors or fruit. So all th<strong>at</strong> you can do when you compare twoelements is ask if they are the same or not. Design an algorithm th<strong>at</strong> islinear in the number of element-element comparisons in the worst caseth<strong>at</strong> will find a majority if one exists, <strong>and</strong> report th<strong>at</strong> there is no majorityif no such element exists in the list.15.13 Given an undirected graph G, the problem is to determine whether or not Gis connected. Use an adversary argument to prove th<strong>at</strong> it is necessary to look<strong>at</strong> all (n 2 − n)/2 potential edges in the worst case.15.14 (a) Write an equ<strong>at</strong>ion th<strong>at</strong> describes the average cost for finding the median.(b) Solve your equ<strong>at</strong>ion from part (a).15.15 (a) Write an equ<strong>at</strong>ion th<strong>at</strong> describes the average cost for finding the ithsmallestvalue in an array. This will be a function of both n <strong>and</strong> i,T(n, i).(b) Solve your equ<strong>at</strong>ion from part (a).15.16 Suppose th<strong>at</strong> you have n objects th<strong>at</strong> have identical weight, except for oneth<strong>at</strong> is a bit heavier than the others. You have a balance scale. You can placeobjects on each side of the scale <strong>and</strong> see which collection is heavier. Yourgoal is to find the heavier object, with the minimum number of weighings.Find <strong>and</strong> prove m<strong>at</strong>ching upper <strong>and</strong> lower bounds for this problem.15.17 Imagine th<strong>at</strong> you are organizing a basketball tournament for 10 teams. Youknow th<strong>at</strong> the merge insert sort will give you a full ranking of the 10 teamswith the minimum number of games played. Assume th<strong>at</strong> each game can beplayed in less than an hour, <strong>and</strong> th<strong>at</strong> any team can play as many games ina row as necessary. Show a schedule for this tournament th<strong>at</strong> also <strong>at</strong>temptsto minimize the number of total hours for the tournament <strong>and</strong> the number ofcourts used. If you have to make a tradeoff between the two, then <strong>at</strong>tempt tominimize the total number of hours th<strong>at</strong> basketball courts are idle.15.18 Write the complete algorithm for the merge insert sort sketched out in Section15.7.15.19 Here is a suggestion for wh<strong>at</strong> might be a truly optimal sorting algorithm. Pickthe best set of comparisons for input lists of size 2. Then pick the best set ofcomparisons for size 3, size 4, size 5, <strong>and</strong> so on. Combine them together intoone program with a big case st<strong>at</strong>ement. Is this an algorithm?

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

Saved successfully!

Ooh no, something went wrong!