Talk:Maximum subarray problem: Difference between revisions

Content deleted Content added
No edit summary
SineBot (talk | contribs)
m Signing comment by 128.138.45.66 - ""
Line 61:
If I pass in an array of entirely negative numbers, e.g. (-1,-1,-1,-1), why wouldn't the maximum sum be -1 instead of 0? <span style="font-size: smaller;" class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/76.247.17.199|76.247.17.199]] ([[User talk:76.247.17.199|talk]]) 22:47, 31 July 2010 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
:Because the [[empty sum]] has a larger total than sums of one or more elements. —[[User:David Eppstein|David Eppstein]] ([[User talk:David Eppstein|talk]]) 23:44, 31 July 2010 (UTC)
:That's not necessarily true. If you want to include negative sums, first increase max_ending_here, then if max_ending_here > max_so_far, replace max_so_far, THEN if max_ending_here < 0, set it to 0. In that way the max will contain the closest negative member to 0 for an all negative array. (Alternatively, you could just find the max member if the resulting max == 0 and it will still be O(n)) -April 9, 2012 <span style="font-size: smaller;" class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/128.138.45.66|128.138.45.66]] ([[User talk:128.138.45.66|talk]]) 04:21, 10 April 2012 (UTC)</span><!-- Template:Unsigned IP --> <!--Autosigned by SineBot-->