Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Exercises 37and38deal with the problem of scheduling the most talks possible given the start and end times of n talks.

Find the complexity of the greedy algorithm for scheduling the most talks by adding at each step the talk with the earliest end time compatible with those already scheduled (Algorithm 7in Section 3.1). Assume that the talks are not already sorted by earliest end time and assume that the worst-case time complexity of sorting is O(nlogn).

Short Answer

Expert verified

O(n2)

Step by step solution

Achieve better grades quicker with Premium

  • Unlimited AI interaction
  • Study offline
  • Say goodbye to ads
  • Export flashcards

Over 22 million students worldwide already upgrade their learning with Vaia!

01

Step 1

Given: is the time complexity of sorting.

Greedy algorithm for scheduling talks.

Procedure- schedule (s1,s2,...,sn:starttimesoftalks,e1>e2>...>en;n:endingtimesoftalks)

Sort talks by finish time and reorder so that e1e2...en.

role="math" localid="1668661065601" S:=ϕ

forj:=1ton

if talk j is compatible with S then

S:=Stalkj

return S.

02

Step 2

SOLUTION

The algorithm makes 1 comparison in each iteration of the for-loop (talk j is compatible with S).

Since j can take on the values from 1 to n, j can take on n values and thus there are most n iterations of the for-loop.

However to determine if talk j is compatible with S, we need to check if every element of S is compatible with talk j which will require at most n - 1 iterations (since S can contain at most n - 1 elements since the nth element will be added after the checks of compatibility).

The number of comparisons is then the product of the number of comparisons per iteration and the number of iterations (Note: product since the loops are nested).

Number of comparisons =1n(n-1)=n(n-1)=n2-n

Now including the complexity of sorting, the time complexity of the algorithm becomes: O(max(n2,nlogn)=O(n2).

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Use the greedy algorithm to make change using quarters, dimes, and pennies (but no nickels) for each of the amounts given in Exercise 53. For which of these amounts does the greedy algorithm use the fewest coins of these denominations possible?

Specify the steps of an algorithm that locates an element in a list of increasing integers by successively splitting the list into four sublists of equal (or as close to equal as possible) size, and restricting the search to the appropriate piece. In a list of elements, the same element may appear several times. A mode of such a list is an element that occurs at least as often as each of the other elements; a list has more than one mode when more than one element appears the maximum number of times.

Show that the following problem is solvable. Given two programs with their input and the knowledge that exactly one of them halts, determine which halts.

Determine which characteristics of an algorithm described in the text(after algorithm 1) the following procedures have and which they lack.

a)proceduredouble(n:positiveinteger)whilen>0n:=2n

b)role="math" localid="1668412435330" proceduredivide(n:positiveinteger)whilen>=0m:=1nn:=2n

c)proceduresum(n:positiveinteger)sum:=0whilei<10sum:=sum+i

d)role="math" localid="1668412892026" procedurechoose(a,b:integer)x:=eitheraorb

Suppose we have three menm1,m2, andm3 and three womenw1,w2,andw3 . Furthermore, suppose that the preference rankings of the men for the three women, from highest to lowest, arem1:w3,w1,w2;m2:w1,w2,w3;m3:w2,w3,w1 and the preference rankings of the women for the three men, from highest to lowest, arew1:m1,m1,m3;w2:m2,m1,m3;w3:m3,m2,m1 . For each of the six possible matchings of men and women to form three couples, determine whether this matching is stable.

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free