Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 92 Implement CutRod(p,n) (page 363) and BottomUpCutRod(p,n) (page 366) in R or Python. Compare running times for a few different values of nn and

Problem 92 Implement CutRod(p,n) (page 363) and BottomUpCutRod(p,n) (page 366) in R or Python. Compare running times for a few different values of nn and report your results. (In R, use the system.time() function.) Use the following values for the price table.

p <- c(1,5,8,9,10,17,17,20,24,30) 

Cut_Rod(p,n)

if n ==0

return 0

q = -infinity

for i = 1 to n

q = max(q,p[i] + Cut-Rod(p,n-i))

return q

---

Bottom-Up-Cut-Rod(p,n)

let r[0..n] be a new array

r[0] = 0

for j = 1 to n

q = - infinity

for i = 1 to j

q = max(q,p[i] + r[ j - i])

r[j] = q

return r[n]

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 Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions