Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Time complexity in recursion

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.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Time #complexity #recursion
ADD COMMENT
Topic
Name
3+3 =