1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mariana [72]
2 years ago
9

Assume that you have a list of n home maintenance/repair tasks (numbered from 1 to n ) that must be done in numeric order on you

r house. You can either do each task i yourself at a positive cost (that includes your time and effort) of c[i] . Alternatively, you could hire a handyman who will do the next 4 tasks for the fixed cost h (regardless of how much time and effort those 4 tasks would cost you). The handyman always does 4 tasks and cannot be used if fewer than four tasks remain. Create a dynamic programming algorithm that finds a minimum cost way of completing the tasks. The inputs to the problem are h and the array of costs c[1],...,c[n] .
a) Find and justify a recurrence (without boundary conditions) giving the optimal cost for completing the tasks. Use M(j) for the minimum cost required to do the first j tasks.

b) Give an O(n) -time recursive algorithm with memoization for calculating the M(j) values.

c) Give an O(n) -time bottom-up algorithm for filling in the array.

d) Describe how to determine which tasks to do yourself, and which tasks to hire the handyman for in an optimal solution.
Computers and Technology
1 answer:
tangare [24]2 years ago
4 0

Answer:

Explanation:

(a) The recurrence relation for the given problem is :

T(n) = T(n-1) + T(n-4) + 1

(b) The O(n) time recursive algorithm with memoization for the above recurrence is given below :

Create a 1-d array 'memo' of size, n (1-based indexing) and initialize its elements with -1.

func : a recursive function that accepts the cost array and startingJobNo and returns the minimum cost for doing the jobs from startingJobNo to n.

Algorithm :

func(costArr[], startingJobNo){

if(startingJobNo>n)

then return 0

END if

if(memo[startingJobNo] != -1)

then return memo[startingJobNo];

END if

int ans1 = func(costArr, startingJobNo+1) + costArr[startingJobNo]

int ans2 = func(costArr, startingJobNo+4) + h

memo[startingJobNo] = min(ans1,ans2);

return memo[startingJobNo];

}

(c)

First, Create a 1-d array 'dp' of size, N+1.

dp[0] = 0

bottomUp(int c[]){

for  i=1 till i = n

DO

dp[i] = min(dp[i-1] + c[i], dp[max(0,i-4)] + h);

END FOR

return dp[n];

}

(d)

Modifying the algorithm given in part (b) as follows to know which job to do yourself and in which jobs we need to hire a handyman.

First, Create a 1-d array 'memo' of size, n (1-based indexing) and initialize its elements with -1.

Next, Create another 1-d array 'worker' of size,n (1-based indexing) and initialize its elements with character 'y' representing yourself.

Algorithm :

func(costArr[], startingJobNo){

if(startingJobNo>n)

then return 0

END if

if(memo[startingJobNo] != -1)

then return memo[startingJobNo];

END if

int ans1 = func(costArr, startingJobNo+1) + costArr[startingJobNo]

int ans2 = func(costArr, startingJobNo+4) + h

if(ans2 < ans1)

THEN

for (i = startingJobNo; i<startingJobNo+4 and i<=n; i++)

DO

// mark worker[i] with 'h' representing that we need to hire a mechanic for that job

worker[i] = 'h';

END for

END if

memo[startingJobNo] = min(ans1,ans2);

return memo[startingJobNo];

}

//the worker array will contain 'y' or 'h' representing whether the ith job is to be done 'yourself' or by 'hired man' respectively.

You might be interested in
Interactive television with video-on-demand capabilities changes how people watch television and how consumers access the Intern
Alex787 [66]

Answer:

High learning

Explanation:

High Learning means that a product require significant customer education before customers understand how the product functions and that may make the product stay longer in the introduction stage whilst the customers are being familiarize with it. Examples are microwave ovens.

6 0
3 years ago
Look at the data set below. {9, 12, 12, 15, 18, 20, 25} in this data set, what is the median
cluponka [151]

. Answer: Median: 15

8 0
3 years ago
Read 2 more answers
Any anime weebs wanna talk
erastova [34]

Answer:

Sowwy, it's not Me!

The Bermuda Triangle, also known as the Devil's Triangle, is a loosely defined region in the western part of the North Atlantic Ocean where a number of aircraft and ships are said to have disappeared under mysterious circumstances. Most reputable sources dismiss the idea that there is any mystery.[1][2][3]

Bermuda Triangle

Devil's Triangle

6 0
2 years ago
Read 2 more answers
Which table option automatically adjusts column widths to fit cell content? autofit contents merge cells autofit window fixed co
noname [10]
Which table option automatically adjusts column widths to fit cell content?
autofit contents
6 0
3 years ago
A malware-infected networked host under the remote control of a hacker is commonly referred to as:
natali 33 [55]

Answer:

Option a: Trojan

Explanation:

A Trojan or Trojan horse is one of the computer malware that exist in computing world. Trojan often appears as a legitimate software to deceive user to activate it by social engineering. Once the Trojan is activated in the user computer, a hacker can remote control the infected computer for malicious purposes such as removing files, sending files, displaying message or rebooting computer.

However, Trojan cannot be replicated in the infected computer.

7 0
3 years ago
Read 2 more answers
Other questions:
  • What saw do you use to cut wood in design and technology
    7·1 answer
  • A recommended cleaner for the bowls of coffee brewers is
    7·1 answer
  • I'd: 9872093250, password: qqqqq, join the meeting​
    11·1 answer
  • Was just testing how this works, no actual question; feel free to take the points anyways though. ​
    13·1 answer
  • Que es una red de datos
    7·2 answers
  • Meera has created a small program in Python. She wants to store elements of the same data type in an organized
    7·1 answer
  • Tại sao xe chỉ sản xuất ra 1996cc mà không phải là 2000cc?
    6·2 answers
  • What are the main differences between openldap and microsoft's active directory (ad)? check all that apply
    13·1 answer
  • Question 1
    5·1 answer
  • which responses would you use for a computer or electronic medical record outage? (select all that apply)
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!