This is the algorithm for finding the maximum contiguous sub-sequence sum using the DP approach. The algorithm seems to be quite okay but it was mentioned that this has space complexity O(n). Why?
To me it seems this algorithm has O(1) space complexity. Another thing that I want to ask is that in case of algorithms which do not use recursion of any sort, can it still be possible for it to have anything other than a constant space complexity?
Create arrays S and T each of size n.
S[0] = A[0];
T[0] = 0;
max = S[0];
max_start = 0, max_end = 0;
For i going from 1 to n-1:
// We know that S[i] = max { S[i-1] + A[i], A[i] .
If ( S[i-1] > 0)
S[i] = S[i-1] + A[i];
T[i] = T[i-1];
Else
S[i] = A[i];
T[i] = i;
If ( S[i] > max)
max_start = T[i];
max_end = i;
max = S[i];
EndFor.
Output max_start and max_end