Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java Implement two versions of the pseudo algorithm of the Rod Cutting Problem in Java use a table below for a sample price with

In java

image text in transcribed

Implement two versions of the pseudo algorithm of the Rod Cutting Problem in Java use a table below for a sample price with pi dollars of revenue for the length i length i 1 2 3 4 5 6 7 8 9 10 price Pi 1 5 8 9 10 17 17 20 24 30 Figure 15.1 A sample price table for rods. Each rod of length i inches carns the company Pi dollars of revenue. A. user will enter a number for n, the size of the rod. b. For each of the two algorithms, determine the optimal revenue rn with the corresponding optimal decompositions of the n and display the revenue and decompositions. c. For each of the two algorithms, count a total number of recursive calls made in determining rn and display/compare them. d. Repeat a-c at least 5 times and show the results. Recursive top-down implementation CUT-ROD(p.n) 1 if n == 0 2 return 0 3 q = - 4 for i = 1 ton 5 q = max(q, pli] + CUT-ROD(p,n i)) 6 return Recursive top-down implementation with memoization MEMOIZED-CUT-ROD (p, n) 1 let r[O..n] be a new array 2 for i = 0 ton 3 r[i] = - 4 return MEMOIZED-CUT-ROD-AUX(p,n,r) auw MEMOIZED-CUT-ROD-AUX(p,n,r) 1 if r[n] > 0 2 return r[n] 3 if n == 0 q=0 else q = -00 6 for i = 1 ton q = max(q, p[i] + MEMOIZED-CUT-ROD-AUX(p.n-i,r)) r[n] = 9 9 return

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

Step: 3

blur-text-image

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions