answersLogoWhite

0


Best Answer

int maxSubArraySum(int a[], int size)

{

int max_so_far = 0, max_ending_here = 0;

int i;

for(i = 0; i < size; i++)

{

max_ending_here = max_ending_here + a[i];

if(max_ending_here < 0)

max_ending_here = 0;

/* Do not compare for all elements. Compare only

when max_ending_here > 0 */

else if (max_so_far < max_ending_here)

max_so_far = max_ending_here;

}

return max_so_far;

}

Time Complexity: O(n)

Algorithmic Paradigm: Dynamic Programming

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you calculate the maximum subarray of a list of numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you calculate the average of a list of numbers?

If you want to calculate the average of a list of numbers, add the numbers together and divide it by the number of numbers.


Is the mean of a list of numbers the maximum minus the minimum?

No. The maximum minus the minimum is the range. The mean is the sum of all elements of the list divided by the size of the list.


What is the math meaning of the word mean?

The mean is when you calculate the sum of a list of numbers and then you didvide by the number of numbers in the list.


How do I find the maximum in a range of numbers?

Compare two numbers, reject the smaller one. Compare the number you are left with and the next one on your list. Keep going to the end. The number you are left with is the maximum.There are other methods.


How do you do average of a lot of numbers?

To find the average of a list of numbers, add the numbers and divide by the number of numbers in the list.


What is the ratio of prime numbers to composite numbers in this list 101112131415161718192021?

what is the ratio or prime numbers to composite numbers in this list/10,11,2,13,14,15,16,1,7,18,19,20,21


What word names in ordered of list of numbers?

An ordered list of numbers is a sequence


What is the formula for calculating average?

[sum of numbers on list] &divide; [amount of numbers in list]


Order list of numbers is called?

Surprisingly, it is called an ordered list of numbers!


How do you find the mode in list of numbers?

It is the number that occurs the most in the list of numbers


Make a list of data with the followng landmarks mode 15 minimum 5 median 10 maximum 20 use at least 10 numbers?

you suck you loser.learn to do your homework!


What is the sum of a list of numbers divided by the total number of numbers in the list called?

Mean