gs gs122 Dynamic Programming - Maximum Sum of Continuous Subarray - Quiz No.1
gs gs122 Data Communication and Computer Network Quiz
This quiz belongs to book/course code gs gs122 Data Communication and Computer Network of gs organization. We have 268 quizzes available related to the book/course Data Communication and Computer Network. This quiz has a total of 17 multiple choice questions (MCQs) to prepare and belongs to topic Dynamic Programming. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
#include<stdio.h> 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 < len; idx++) sum[idx] = _______________________; int mx = sum[0]; for(idx = 0; idx < len; idx++) if(sum[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; }
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;
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;
Which method is used by line 4 of the above code snippet?