Yuckdonald’s is considering opening a series of restaurant along Quaint Valley Highway(QVH). The n possible locations are along a straight line, and the distances of these locations from the start of QVH are, in miles and in increasing order,m1,m22,....,mn.. The constraints are as follows:

At each location, Yuckdonald may open at most one restaurant. The expected profit from opening a restaurant at location i is given aspi, wherepi>0andi=1,2,,n.

Any two restaurants should be at least k miles apart, where k is a positive integer.

Give an efficient algorithm to compute the maximum expected total profit subject to the given constraints.

Short Answer

Expert verified

In this question certain thing we need to notice,

  • “At each location, Yuckdonald may open at most one restaurant”.

This means either no restaurant or at most one restaurant can be opened in each location.

  • “Any two restaurants should be at least k miles apart, where k is a positive integer”.

This means if suppose there are two location and, then each restaurant can be open only if:

distance(mn)-distance(mm)>=k

Step by step solution

01

Defining base condition and constraints mathematically

Let us supposeP(i)be the maximum profit Yuckdonald can fetch from restaurants that are open in location from 1 to i.

So ifi=0, this implies that there is no location available to open a restaurant.

ThusP(0)=0i.e., Profit is 0 as no restaurant is open.

So based on our constraints we will define a recursion relation,

P(i)=MAX{(MAXi<j(P(j)+β(mi,mj).pi)pi

Here,

role="math" localid="1657267434540" P(j)=Maximumprofitobtainfromlocationj

But if profit obtain from location ‘i’ is more then location ‘j’ or if it’s not possible to locate restaurant at location ‘j’, then ‘pi’ will be our maximum profit.

Here, symbol βwill define whether there can be a restaurant at location i .

So we defineβas:

β={0;if(mi-mj)<k1;if(mi-mj)>k

02

Implement the algorithm

We will initiate an arrayProfit[]that will tell about expected profit from location ‘i’

Here, v variable will store temporary value ofProfit[i] .

fori=1toNProfit[i]=0fori=2toNforj=1toi-1v=(Profit[j]+β(mi,mj).P[i])ifv>Profit[i]v=Profit[i]ifProfit[i]<P[i]Profit[i]=P[i]

Since two loops are executing here, so collectively the time complexity is O(n2).

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

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

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

Counting heads. Given integersn and k, along with p1,...,pn[0,1], you want to determine the probability of obtaining exactly heads when biased coins are tossed independently at random, where pi is the probability that the ith coin comes up heads. Give an 0(n2)algorithm for this task. Assume you can multiply and add two numbers in [0,1]in 0(1)time.

The garage sale problem (courtesy of Professor Lofti Zadeh). On a given Sunday morning, there are n garage sales going on, g1,g2,g3............gn. For each garage sale gj, you have an estimate of its value to you, vj. For any two garage sales you have an estimate of the transportation cost dijof getting from gito gj. You are also given the costs d0jand dj0of going between your home and each garage sale. You want to find a tour of a subset of the given garage sales, starting and ending at home, that maximizes your total benefit minus your total transportation costs. Give an algorithm that solves this problem in time O(n22n).

(Hint: This is closely related to the traveling salesman problem.)

Let us define a multiplication operation on three symbols a,b,caccording to the following table; thus ab=b,ba=c, and so on. Notice that the multiplication operation defined by the table is neither associative nor commutative.

Find an efficient algorithm that examines a string of these symbols, say bbbbac, and decides whether or not it is possible to parenthesize the string in such a way that the value of the resulting expression is . For example, on input bbbbacyour algorithm should return yes because((b(bb))(ba))c=a.

Consider the following 3-PARTITION problem. Given integersa1,...,an, we want to determine whether it is possible to partition of {1,...,n} into three disjoint subsets I,J,Ksuch that

aiiI=ajjJ=akkk=13aii1 .

For example, for input(1,2,3,4,4,5,8) the answer is yes, because there is the partition(1,8),(4,5),(2,3,4). On the other hand, for input(2,2,3,5) the answer is no. Devise and analyze a dynamic programming algorithm3-PARTITION for that runs in time polynomial in n and in Σiai.

Given two strings x=x1x2···xnand y=y1y2···ym, we wish to find the length of their longest common substring, that is, the largest k for which there are indices i and j with xixi+1···xi+k-1=yjyj+1···yj+k-1. Show how to do this in time0(mn)

See all solutions

Recommended explanations on Computer Science 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