Examveda

Consider the following code snippet. Which property is shown by line 4 of the below code snippet?
1. int sum[len], idx;
2. sum[0] = arr[0];
3. for(idx = 1; idx < len; idx++)
4.	  sum[idx] = max(sum[idx - 1] + arr[idx], arr[idx]);
5. int mx = sum[0];
6. for(idx = 0; idx < len; idx++)
7.	 if(sum[idx] > mx)
8.		mx =sum[idx];
9. return mx;

A. Optimal substructure

B. Overlapping subproblems

C. Both overlapping subproblems and optimal substructure

D. Greedy substructure

Answer: Option A


Join The Discussion

Related Questions on Dynamic Programming in Data Structures