Vidyalelo
Data Structure · Q99

Dynamic Programming in Data Structures

Programming · Data Structure · question 99

Q99

What is the space complexity of the following dynamic programming algorithm used to find the maximum sub-array sum? #include int max_num(int a,int b) if(a> b) return a; return b; int maximum_subarray_sum(int *arr, int len) int sum[len], idx; sum[0] = arr[0]; for(idx = 1; idx mx) mx =sum[idx]; return mx; int main() int arr[] = -2, -5, 6, -2, 3, -1, 0,-5, 6, len = 9; int ans = maximum_subarray_sum(arr, len); printf("%d",ans); return 0;

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

Answer: Option A

Solution

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