0
$\begingroup$

Suppose I have two mutually recursive functions like this:

f1(x)
{
   .//some code
   .
   .
   f1(x-1)+g1(x-1); 

}

g1(y)
{
   .
   .//some code
   g1(y-1)+f1(y-1);
  ..


}

How can I calculate time complexities in such cases?

$\endgroup$
1
$\begingroup$

If we set up recurrences, $T_1(n) = T_1(n-1) + T_2(n-1)$ and $T_2(n) = T_1(n-1) + T_2(n-1)$. So from there we can get that $T_1(n) = T_2(n)$, which implies that $T_1(n) = 2T_1(n-1)$. So for this, the two functions would be $O(2^n)$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.