Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose that in the rod-cutting problem, we also had limit l_i on the maximum number of pieces of length i we are allowed to produce,

Suppose that in the rod-cutting problem, we also had limit l_i on the maximum number of pieces of length i we are allowed to produce, for i=1,2,...,n. Write a dynamic program for this modified problem.

image text in transcribedimage text in transcribed

Recursive top-down implementation The following procedure implements the computation implicit in equation (15.2) in a straightforward, top-down, recursive manner. CUT-ROD(p, n) 1 if n return 0 3 4 for 1 to n 5 max (q, plij CUT-RoD(p, n i)) 6 return Procedure CUT RoD takes as input an array pl1..nl of prices and an integer n, and it returns the maximum revenue possible for a rod of length n. If n 0, no revenue is possible, and so CUT-ROD returns 0 in line 2. Line 3 initializes the maximum revenue to -oo, so that the for loop in lines 4 5 correctly computes maxi Sisn (pi CUT-RoD(p, n -i)); line 6 then returns this value. A simple induction on n proves that this answer is equal to the desired answer rn, using equation (15.2) If you were to code up T-ROD in your favorite programming language and run it on your computer, you would find that once the input size becomes moderately large, your program would take a long time to run For n 40, you would find that your program takes at least several minutes, and most likely more than an hour. I fact, you would find that each time you increase n by 1, your program's running time would approximately double Why is CUT-RoD so inefficient? The problem is that CUT-RoD calls itself recursively over and over again with the same parameter values, it solves the same subproblems repeatedly. Figure 15.3 illustrates what happens for n 4: CUT-RoD(p,n) calls CUT-RoD(p,n i) for i 1,2 n. Equivalently, CUT-RoD(p, n) calls CUT-RoD(p, j) for each j 0,1 ...,n -1. When this process unfolds recursively, the amount of work done, as a function of n, grows explosively. To analyze the running time of CUT RoD, let TOn) denote the total number of calls made to CUT-ROD when called with its second parameter equal to n. This expression equals the number of nodes in a subtree whose root is labeled n in the recursion tree. The count includes the initial call at its root. Thus, T (0) l and

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago

Question

4. Show the trainees how to do it again.

Answered: 1 week ago