I'm kinda new to analyse algorithm and i wrote a different version of the Fib serie and i'm not quite sure about the worst case of the running time (assuming the basic operations counted are additions). Here is my code.
int fib(int n){
int tab[n];
if (n<4){
return n;
}
tab[0]=0;
tab[1]=1;
tab[2]=2;
tab[3]=3;
for(int i = 4; i<=n; ++i){
tab[i] = tab[i-2] + (2*tab[i-4]) + 3;
}
return tab[n];
}
I will say that the worst case here is W(n)= 2n-4
but..i really dont know. How do i analyse it properly?