Problem 6. Show that, after cL1], c[2], cn are computed (using Cut Road or Memoi
ID: 3862554 • Letter: P
Question
Problem 6. Show that, after cL1], c[2], cn are computed (using Cut Road or MemoizedCut), the best cutting of a rod of length n can be printed in O(n) time using only O(1) additional memory. CutRod(n) Memoized Cut(n) 1 make a new array cl0..nl 1 if cIn] 0 then return c already computed In] 2 if n 0 then return 0 the base case 3 for j 1 to n 3 cost 0 to compute the max cost 4 cost 0 for i 1 to n for i 1 to j cost F max cost, pli]-+MemoizedCut (n i cost max(cost, plil cli -ij) 6 cin cost 7 clil cost return cost 8 return cn Please answer the questions completely and thoroughly giving explanations along the way. This is the second time I have posted this...the first I received a non-sense answer. Both algorithms listed in the question are provided as well. I will give positive feedback for a clear and thorough explanation. Please do not answer the question unless the answer is complete. Thank you in advance for your help.Explanation / Answer
Step1:Take new Array with size o...n Like c[0..n]
step2:Array index value Start with zero and initization of Array with 0
step3:repeat the loop from 0 to n
step4:init cost value=0.That means its start with oth to nth cost
step5:find max cost from n iterations using with recursion function
step6:this recursion function call it self
it have some conditions show on other side,base=0 .it repeat n iterations from 0 to n using with i variable.
step7:in case n=0 or c[n]>0 its not find cost
other wise find max return it.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.