Vidyalelo
Data Structure · Q235

Dynamic Programming in Data Structures

Programming · Data Structure · question 235

Q235

What is the space complexity of the following dynamic programming implementation of the rod cutting problem? #include #include int rod_cut(int *prices, int len) int max_val[len + 1]; int i,j,tmp_price,tmp_idx; max_val[0] = 0; for(i = 1; i tmp_max) tmp_max = tmp_price; max_val[i] = tmp_max; return max_val[len]; int main() int prices[]=2, 5, 6, 9, 9, 17, 17, 18, 20, 22,len_of_rod = 5; int ans = rod_cut(prices, len_of_rod); printf("%d",ans); return 0;

A.
O(1)
B.
O(n)
Answer
C.
O(n2)
D.
O(2n)

Answer: Option B

Solution

Answer: Option B
No explanation is given for this question Let's Discuss on Board