Time complexity of a recursive function depends on the number of times the
function is calling himself multiply this by the each time how many time
complexity is taken on each call it can be O(1), O(log n), O(n) or more.
Let's say our function is calling n-1 times and each it is doing some
comparisons and call it self again. So function itself has a time complexity of
O(1).
So the total time complexity will be (n-1)*1 which is o(N).
void recursiveFun4(int n, int m, int o)
{
if (n <= 0)
{
printf("%d, %d
",m, o);
}
else
{
recursiveFun4(n-1, m+1, o);
recursiveFun4(n-1, m, o+1);
}
}
Here, it's O(2^n), or exponential, since each function call calls itself twice unless it has been recursed n times.
Recursion Tree Method
(To solve recurrence and get time complexity of recursive function)
1)We write non-recursive part as root of tree and recursive part as it's children.
Then take sum of nodes in each level & find Sum of these sums of each level
generally terms of thi new Sum will be in ap,gp etc with number of terms as height of tree.
Note : if recursive part is T(n/2) then height of tree is log(n)
if it's T(n-1) then height is n.
2)We keep on expanding Children untill we reach the base case ( aka leaves ).
T(n) = 2T(n-1) + cn
T(1) = c
Where cn is non recursive part.
Note : instead of 0(1) we write constant c, for 0(n) we write cn
Keep c same everywhere.