Maximum interval sum

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
New poster
Posts: 2
Joined: Sat Nov 06, 2010 12:54 am

Maximum interval sum

Post by akashs »

pls anyone tell the basic step in the maximum interval sum.

sir. manuel
New poster
Posts: 18
Joined: Sat Nov 20, 2010 7:44 pm

Re: Maximum interval sum

Post by sir. manuel »

This code,,,it's linear!!!

n= number of elements
maxsum=-INF; INF=it's the element minimum of all posibles cases
for(int i=0;i<n;i++){
if(sum>0){ sum+=element; }
else{ sum=element; }

maxsum it's the maximum sum!!!

There is a algorithm of n²,n³...

Post Reply

Return to “Algorithms”