the maxsubsum problem
maximize(summation of A from j to k )=maximize(summation of A from 0 to k)
-minimize(summation of A from 0 to j-1)
size_t maxsum = a[0];
size_t minsum=0;
size_t maxend=0;
size_t minend=-1;
size_t cursum= maxsum;
for (int i=1;i<n;i++)
{
cursum+=a[i];
if (cursum - minsum > maxsum)
{
maxsum = cursum; maxend = i;
}
if (cursum < minsum)
{
minsum = cursum;
minend=i;
}
}
so the maxsubsum is from minend+1 to maxend
Q1. should the highlighted if be else //of if (cursum - minsum > maxsum).
Will it make any difference?
Q2. should cursum<minsum be done before the previous if check? Will there be
a case when minend and maxend both with move together?
Q3. What will be the test cases to test this function?
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.