-1

I have written a program in C to solve the maximum sub-array problem. This solution is of O(N^3) complexity. Is there any way to approximate the run time for N = 1,000,000? I know there are much faster algorithms than that of third order but I need to compare those to my current program.

int MaxSubSlow(){
    int max_so_far = 0,i,j,k,temp_sum;


    for(j=1;j<N;j++){   
        for(k=j;k<N;k++){
            temp_sum = 0;
            for(i=j;i<k;i++){
                temp_sum += A[i];
            }   
            if(temp_sum > max_so_far){
                max_so_far = temp_sum;      
            }
        }
    }


    return max_so_far;
}
Thomas Padron-McCarthy
  • 27,232
  • 8
  • 51
  • 75
Shivalnu
  • 119
  • 2
  • 16

1 Answers1

1

If it is O(N^3) you can approximate N=1,000,000 by running it with N=1,000 and then multiply by 1,000,000,000. (But, since the O notation can hide other significant terms except the N^3 one, you can't be sure that it is a very good approximation.)

Thomas Padron-McCarthy
  • 27,232
  • 8
  • 51
  • 75