int noOfWays(int n)
{
if(n==1)
return 1;
else if(n==4)
return 2;
else if (n<=0)
return 0;
return noOfWays(n-1)+noOfWays(n-4);
}
how to calculate time complexity of this code
int noOfWays(int n)
{
if(n==1)
return 1;
else if(n==4)
return 2;
else if (n<=0)
return 0;
return noOfWays(n-1)+noOfWays(n-4);
}
how to calculate time complexity of this code
@dare_devil_007 As you can see in this question that this is a recursive solution. This can be solved using master theorem for recursive solutions.
I would recommend you to just learn about masters theorem. It would help you to understand time complexity in a better way
Well the time complexity is 0(n)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.