Content deleted Content added
→History is weird: new section |
m Replaced deprecated <source> tags with <syntaxhighlight> (via WP:JWB) |
||
Line 5:
In the O(n) algorithm, s (the largest calculated sum so far) is initialized as follows:
<
int s=1<<31;
</syntaxhighlight>
First, this assumes that each integer is exactly 4 bytes wide, which is not the case for all architectures.
Line 16:
: I've struck out my second proposition, which would fail for sequences having exactly one element. For my first proposition, I think s is best initialized to -Infinity as (for C++)
: <
int s = numeric_limits<int>::min()
</syntaxhighlight>
: or to MIN_INT in C
Line 32:
The correct algorithm is:
<
Kadane_s_Algorithm(arr[1..n])
begin
Line 52:
return (max, a, b)
end
</syntaxhighlight>
|