The maximum subarray problem
Given an array of integers, some possibly negative, find a contiguous subarray with the largest sum. For example, in the best subarray is with sum 6. Give an algorithm and prove it correct.
History and references
Solved by Jay Kadane.
Ulf Grenander proposed the problem in 1977 as a simplified model for detecting patterns in digitized images. Grenander had an method, Michael Shamos found an divide-and-conquer algorithm, and Jay Kadane then found a linear-time algorithm after hearing Shamos describe the problem at Carnegie Mellon. Jon Bentley told the story in his Programming Pearls column in Communications of the ACM in 1984. Kadane's algorithm scans from left to right and keeps the best sum of a subarray ending at the current position, which is either the current element alone or the current element plus the previous best. The answer is the largest of these running values.
References
Solutions 0
Sign in or create an account to publish a solution