answer.
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]
1 year 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]1 year 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
What are the arguments for writing efficient programs even though hardware is relatively inexpensive?
Ainat [17]

Answer: Even though the hardware is inexpensive the writing of program is not efficient through this method as proper development of program is necessary for the clear execution due to factors like:-

  • The facility of writing program even the cost of hardware is less but it is not a free facility.
  • It also has a slower processing for the execution of the program
  • The construction of the efficient program is necessary for the compilation and execution of it rather than poorly constructed program is worthless and inefficient in working.

7 0
1 year ago
my headphones have a mic and the mic and headset don't work at the same time what do i do to make them work together
JulsSmile [24]
Return them they are probably defective or turn ur media volume all the way down.
6 0
1 year ago
Read 2 more answers
In the Budget Details sheet, if you wish to autofill with the formula, you must use a ______ reference for the LY Spend Total ce
ahrayia [7]

Answer:

The answer is A.Absolute reference.

Explanation:

Absolute reference is a cell reference whose location remains constant when the formula is copied.

8 0
2 years ago
John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastructure issues.
lisov135 [29]

Answer:

Hardware.

Explanation:

All electronics devices like computer servers, DVDs, smartphones and cell phones, wrist watches etc, comes with two main components, they are hardware and software.

The hardware components are the physical part of the device, while the software component is the written instructions configured to the hardware for executing tasks.

Cleaning the motherboard in a computer system, fixing a DVD, servicing other internal components of devices are all hardware maintenance and repair services.

6 0
1 year ago
Which of the following is a true statement about cloud computing?
Veseljchak [2.6K]

Answer:

There are additional security risks associated with using cloud computing over local data storage.                    

Explanation:

Cloud computing: The term "cloud computing" is described as a process through which an individual tends to access and store various programs and data over the internet rather than his or her computers' "hard drive". However, the term "cloud" here refers to a specific metaphor associated with the internet.

Types:

1. Software-as-a-service or SaaS.

2. Platform-as-a-service or PaaS.

3. Infrastructure-as-a-service or IaaS.

In the question above, the very first option is correct as all other options mentioned over here are incorrect because they aren't related to cloud computing.

3 0
1 year ago
Other questions:
  • Which of the following word pairs correctly completes the sentence below?
    15·2 answers
  • A business wants to centralize its administrative tasks. At the same time, it wants the existing systems to manage and sustain t
    14·2 answers
  • You are given an array x of string elements along with an int variable n that contains the number of elements in the array. You
    11·1 answer
  • Consider a single-platter disk with the following parameters: rotation speed: 7200 rpm; number of tracks on one side ofplatter:
    10·1 answer
  • You realize your computer has been infected with malware. It seems as if someone is controlling your computer from a remote loca
    5·1 answer
  • Some early computers protected the operating system by placing it in a memory partition that could not be modified by either the
    5·1 answer
  • A summer camp offers a morning session and an afternoon session.
    5·1 answer
  • ANSWER AS SOON AS POSSIBLE: When I try to join roblox adopt me it says: "Roblox Datastore servers are currently down. Please rej
    10·2 answers
  • 1. Write a set of routines for implementing several stacks and queues within a single array. Hint: Look at the lecture material
    15·1 answer
  • Which characteristic of Cloud computing allows data centers to better manage hard drive failures and allocate computing resource
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!