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.

A subsequence is palindromic if it is the same whether read left to right or right to left. For instance, the sequence

A,C,G,T,G,T,C,A,A,A,A,T,C,G

has many palindromic subsequences, including A,C,G,C,Aand A,A,A,A(on the other hand, the subsequence A,C,Tis not palindromic). Devise an algorithm that takes a sequence X[1...n]and returns the (length of the) longest palindromic subsequence. Its running time should be0(n2).

You are given a convex polygon P on n vertices in the plane (specified by their x and y coordinates). A triangulation of P is a collection of n-3diagonals of such that no two diagonals intersect (except possibly at their endpoints). Notice that a triangulation splits the polygon’s interior into n-2 disjoint triangles. The cost of a triangulation is the sum of the lengths of the diagonals in it. Give an efficient algorithm for finding a triangulation of minimum cost. (Hint: Label the vertices of P by 1,....,n, starting from an arbitrary vertex and walking clockwise. For 1i<jn, let the subproblem A(i,j)denote the minimum cost triangulation of the polygon spanned by vertices i,i+1,...,j.).

Alignment with gap penalties. The alignment algorithm of Exercise 6.26 helps to identify DNA sequences that are close to one another. The discrepancies between these closely matched sequences are often caused by errors in DNA replication. However, a closer look at the biological replication process reveals that the scoring function we considered earlier has a qualitative problem: nature often inserts or removes entire substrings of nucleotides (creating long gaps), rather than editing just one position at a time. Therefore, the penalty for a gap of length 10 should not be 10 times the penalty for a gap of length 1, but something significantly smaller.

Repeat Exercise 6.26, but this time use a modified scoring function in which the penalty for a gap of length k is c0 + c1k, where c0 and c1 are given constants (and c0 is larger than c1).

Consider the following variation on the change-making problem (Exercise 6.17): you are given denominations x1,x2,...,xn, and you want to make change for a value v, but you are allowed to use each denomination at most once. For instance, if the denominations are 1,5,10,20,then you can make change for 16=1+15and for 31=1+10+20but not for 40(because you can’t use 20 twice).

Input: Positive integers; x1,x2,...,xnanother integer v.

Output: Can you make change for v, using each denominationxi at most once?Show how to solve this problem in time O(nV).

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