Find the maximum subarray sum for the given elements. {2, -1, 3, -4, 1, -2, -1, 5, -4}
Answers
Answered by
3
-1
Explanation:
please mark as brainlist
Answered by
0
Answer:
The maximum subarray sum is 1 of the subarray {5,-4}.
Arrays:
- An array is a set or group of identical elements which are stored under a common variable name.
- All array elements are of the same data type.
- The array elements are accessed through the index number. The index number always starts from 0.
- The final index number is always one less than the number of total elements stored in the array.
- A subarray is simply a small part of an array.
Explanation:
- The given array elements are {2, -1, 3, -4, 1, -2, -1, 5, -4}.
- There are 9 subarrays. They are
- {2, -1, 3, -4, 1, -2, -1, 5, -4}
- {-1, 3, -4, 1, -2, -1, 5, -4}
- {3, -4, 1, -2, -1, 5, -4}
- {-4, 1, -2, -1, 5, -4}
- {1, -2, -1, 5, -4}
- {-2, -1, 5, -4}
- {-1, 5, -4}
- {5, -4}
- {-4}
- The sum of the subarray {2, -1, 3, -4, 1, -2, -1, 5, -4} is -1.
- The sum of the subarray {-1, 3, -4, 1, -2, -1, 5, -4} is -3.
- The sum of the subarray {3, -4, 1, -2, -1, 5, -4} is -2.
- The sum of the subarray {-4, 1, -2, -1, 5, -4} is -5.
- The sum of the subarray {1, -2, -1, 5, -4} is -1..
- The sum of the subarray {-2, -1, 5, -4} is -2.
- The sum of the subarray {-1, 5, -4} is 0.
- The sum of the subarray {5, -4} is 1.
- The sum of the subarray {-4} is -4.
- The maximum subarray sum is for the subarray {5, -4} and the sum is 1.
The maximum subarray sum for the given elements is 1.
#SPJ2
Similar questions