What is the time complexity to compute this function for n.
int rec(int n)
{
if (n<=1) {
return n ;
}
int i;
int sum=0;
for (i=1; i<n; i++) {
sum=sum+rec(i);
}
return sum ;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
well let’s break this out
however,
so plugging (2) into (1) gives
and f(2) = 1, so this is clearly 2n (for details: Can not figure out complexity of this recurrence). well, actually 2n-1 but in big O, it doesn’t quite matter because the -1 is the same as /2.