Question
A.) show that the following algorithm does not correctly solve this problem, by giving an instance on which it does not return the correct answer

B.) Give an efficient algorithm that takes values for l1, l2,...,ln and h1, h2, hn and returns the value of an optimal plan
Suppose youre managing a consulting team of expert computer hackers, and each week you have to choose a job for them to undertake. Now, as you can well imagine, the set of possible jobs is divided into those that are low-stress (e.g., setting up a Web site for a class at the local elementary school) and those that are high-stress (e.g., protecting the nations most valuable secrets, or helping a desperate group of Cornell students finish a project that has something to do with compilers). The basic question, each week, is whether to take on a low-stress job or a high-stress job. If you select a low-stress job for your team in week i, then you get a revenue of I > 0 dollars; if you select a high-stress job, you get a revenue of hi > 0 dollars. The catch, however, is that in order for the team to take on a high-stress job in week i, its required that they do no job (of either type) in week i-1; they need a full week of prep time to get ready for the crushing stress level. On the other hand, its okay for them to take a low-stress job in week i even if they have done a job (of either type) in week i 1 So, given a sequence of n weeks, a plan is specified by a choice of low-stress, high-stress, o none for each of the n weeks, with the property that if high-stress is chosen for week i > 1, then none has to be chosen for week i - 1. (Its okay to choose a high-stress job in week 1.) The value of the plan is determined in the natural way: for each i, you add I to the value if you choose low-stress in week I, and you add h to the value if you choose high-stress in week i. (You add 0 if you choose none in week i.) The problem. Given sets of values 11, i2.,., .in and h1, h2,.., hn, find a plan of maximum value. (Such a plan will be called optimal.) Example. Suppose n 4, and the values of li and hi are given by the following table. Then the plan of maximum value would be to choose none in week 1, a high-stress job in week 2, and low-stress jobs in weeks 3 and 4. The value of this plan would be O+50+ 10+10-70. Week 1 Week 2 Week 3 Week 4 1 |10 10 10 50 5 (a) Show that the following algorithm does not correctly solve this on which it does not return the correct answer problem, by giving an instance
media%2Fb8b%2Fb8b9c506-8949-4a9b-b2a7-9b
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(A)

The described algorithm will not return the particular value or profit because there is no such statement that calculates the total value, the algorithm only selects the job as per condition.

(B)

Algorithm:

if No== 1
   then
   tempSolution= max(l[No],h[No])
else if No== 2 then
   tempSolution= max(optimalPlan(1, l, h)+ l[2], h[2])
else
   tempSolution= max(optimalPlan(No− 1, l, h) + l[No], optimalPlan(No− 2, l, h) + h[No])
end if
return Value


FindOptimalValue(No, l, h)

//Initialisation
for itterator = 1 ! No do
   tempSolution[itterator] = 0
end for

for itterator = 1 ! No do
   if itterator == 1 then
       tempSolution[itterator] max(l[itterator], h[itterator])
   else if itterator == 2 then
       tempSolution[itterator] max(tempSolution[1] + l[2], h[2])
   else
       tempSolution[itterator] max(tempSolution[itterator − 1] + l[itterator], tempSolution[itterator − 2] + h[itterator])
   end if
end for

return Value[No]
//Recurrsive function to find the optimal plan
OPtimalPlan(No, l, h, Value)

for itterator = 1 ! number do
   WeekVal[itterator]
end for
if tempSolution[No] − l[No] = tempSolution[No− 1] then
   WeekVal[No] ”Low stress”
   OPtimalPlan(No-1, l, h, Value)
else
   WeekVal[No] ”High stress”
   OPtimalPlan(No-2, l, h, Value)
end if
return WeekVal

Explanation:

  • The optimal solution of the above algorithm is the maximum value of low-stress jobs and the high stress jobs.
  • For the first week, the maximum of low-stress job and the high-stress job value is chosen. After the first week, the optimal solution between both the jobs is being chosen.
  • For the optimal solution, the function FindOptimalValue(n, l, h) is defined and called and return the maximum value of the particular week.
  • For the optimal plan, a function FindOptimalPlan(n, l, h, Value) is defined and output the weeks and the status of each job.
Add a comment
Know the answer?
Add Answer to:
A.) show that the following algorithm does not correctly solve this problem, by giving an instance...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Decrease-by-Half Algorithm We can solve the same problem using a decrease-by-half algorithm. This...

    Convert the pseudocode into a C++ function Decrease-by-Half Algorithm We can solve the same problem using a decrease-by-half algorithm. This algorithm is based on the following ideas: In the base case, n 1 and the only possible solution is b 0, e 1 In the general case, divide V into a left and rnight half; then the maximum subarray can be in one of three places: o entirely in the left half; o entirely in the right half; or o...

  • You are given an algorithm that uses T(n) a n2b.3" basic operations to solve a problem...

    You are given an algorithm that uses T(n) a n2b.3" basic operations to solve a problem of size n, where a and b are some real non-negative constants. Suppose that your machine can perform 400,000,000 basic operations per second (a) If a = b = 1, how long does it take for your algorithm to solve problems of size n = 10, 20, 50. For each size of n, include the time in seconds and also using a more appropriate...

  • You're in charge of running a scientific program (job) that simulates a physical system for as ma...

    You're in charge of running a scientific program (job) that simulates a physical system for as many discrete steps as you can. The lab you're working in has two large supercomputers, which we'll call A and B, which are capable of processing this job. However, you're not one of the high-priority users of these supercomputers, so at any given point in time, you're only able to use as many spare cycles as these machines have available. Here's the problem you...

  • How much time does the following "algorithm" require as a function Problem 4.1. of n? for...

    How much time does the following "algorithm" require as a function Problem 4.1. of n? for i 1 to n do for j 1 to n do for k 1 to n3 do Express your answer in 6 notation in the simplest possible form. You may consider that each individual instruction (including loop control) is elementary

  • showing the path of the left-turning algorithm and the path of the right-turning algorithm. A switching...

    showing the path of the left-turning algorithm and the path of the right-turning algorithm. A switching Bug 0 algorithm (25 points). E1.2 (i) (10 points) Draw a flowchart for the following pseudo-code implementation of the switching Bug 0 algorithm: 1: choose an initial direction (either left or right) 2: while not at goal : move towards the goal if hit an obstacle : while not able to move towards goal : take a step along the obstacle boundary moving in...

  • Final Project: Personal Stress Management Report The purpose of this project is to discover the impact...

    Final Project: Personal Stress Management Report The purpose of this project is to discover the impact of the regular practice of a stress-reducing technique. • This project is worth 30% of your final grade. • Please submit a typed-up report of all the sections addressed below. • Due date: A) Choose 1 stress-reducing technique from the list below: • Meditation: try a guided meditation from Insight Timer, Calm, 10% happer Apps, or try unguided meditation by yourself. • Journalling •...

  • 6. Consider the following basic problem. You're given an array A consisting of n integers A[1],...

    6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i <j) contains the sum of array entries Ali] through Aj]-that is, the sum A[i] Ai 1]+ .. +Alj]. (The value of array entry B[i. Λ is left unspecified whenever i >j, so it doesn't matter what is output for these values.) Here's a simple algorithm to...

  • Hi, I need help with this practice problem! Chapter 2 Algorithm Discovery and Design 64C FIGURE...

    Hi, I need help with this practice problem! Chapter 2 Algorithm Discovery and Design 64C FIGURE 2.10 Get values for a and b If (either a 0orb 0) then Set the value of product to o se Set the value of count to 0 Set the value of product to 0 While (count <b) do Set the value of product to (product+ a) Set the value of count to (count + 1) End of loop Print the value of product...

  • WEEK 6: COURSE PROJECT The Week 6 portion of your Course Project is due this week....

    WEEK 6: COURSE PROJECT The Week 6 portion of your Course Project is due this week. Please refer to the Course Project Overview in the Introduction and Resources module for full details. Use this report (Links to an external site.)Links to an external site. to complete this portion of the project. Guess the number! You will add to the program you created last week. This week you will add quite a bit of code to your project. You will add...

  • Enteral Nutrition 1. Rhonda is a 67yo retiree recently involved in an MVA. She’s comatose in...

    Enteral Nutrition 1. Rhonda is a 67yo retiree recently involved in an MVA. She’s comatose in the neuro ICU and her medical team is concerned about cerebral edema. As a result, they’ve placed her on a severe fluid restriction. Rhonda’s prognosis is sketchy; she’s been in a coma for 2d already, her O2 sats are dipping and your team has decided to intubate and place her on mechanical ventilation. The good news is that she does have bowel sounds and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT