1
I need to calculate the time consumption of the following algorithm:
int somaSequencial(int v[],int n){
int m = 0;
for(int i = 0; i < n; i++){
for(int j = i; j < n; j++){
int s = 0;
for(int k = i; k <= j; k++){
s+= v[k];
}
if(s > m){
m = s;
}
}
}
return m;
}
After naming each operation, from t1 to T15, I came to the following conclusion:
F(n) = a + b(n) + c(n/2)(n+1) + d[ "Sum from i=1 to n" (n/2)(n+1)]
I would like to know if it is correct, since it is a cubic algorithm.
It has a very simple method to evaluate the behavior of this function. Remove the variables
m
ands
, declare at firstpassosLoop3 = 0
andpassosLoop2 = 0
. Instead of making the sum ins
, dopassosLoop3++
. In place ofif
, dopassosLoop2++
. Test for some controlled values ofn
and make the polynomial interpolation that meets thepassosLoop3
andpassosLoop2
– Jefferson Quesado
@Jeffersonquesado You can even enter the numbers on that website there, what he does to it for himself. Apparently this is something like
x^3/6+x^2/2+x/3
– Bruno Costa
@Brunocosta interesting the site, I will analyze more calmly after leaving work
– Jefferson Quesado
Bruno Costa, how to use this site?
– Kfcaio