How to find the complexity of an the given algorithm:
Algorithm f(int n)
{
if(n==1)return(1);
else
{
f(n-1)+g(n-1);
}
}
Algorithm g(int n)
{
if(n==2)return(1);
else
{
f(n-1)+g(n/2);
}
}
The answer is O(2^n), But how?
How to find the complexity of an the given algorithm:
Algorithm f(int n)
{
if(n==1)return(1);
else
{
f(n-1)+g(n-1);
}
}
Algorithm g(int n)
{
if(n==2)return(1);
else
{
f(n-1)+g(n/2);
}
}
The answer is O(2^n), But how?
Copyright © 2021 JogjaFile Inc.
Set up two variables (for $f$ and $g$) and define a system of recurrences.