What's the time complexity of the following two functions?
int fun1(int n){
if(n>0)
return (2*fun1(n-1)+1);
else return 1;
}
int fun2(int n){
if(n>0)
return (fun2(n-1)+fun2(n-1)+1);
else return 1;
}
Obviously for fun2 we write recursive equation as T(n) = 2*T(n-1) + 1 but how do we write recursive equation for fun1?
You're correct about fun2.
For fun1, think about your usual rules of math, disregard time complexity. 2*fun1(n-1) = fun1(n-1) + fun1(n-1), unless rules of multiplication can redefined, such as in modern analysis (I believe that's the vein of mathematics that's taught in. Been a while since I was in that class :) )
So with the distribution rule, fun1 is effectively the same as fun2, thus having the same time complexity.