GATE Exam | Aptitude Questions | GATE Syllabus | GATE Result | Mock Test | GATE Preparation
0 votes

Consider the following C-function:

double foo (int n)

{

    int i;

    double sum;

    if (n = = 0) return 1.0;

    else

    {

        sum = 0.0;

        for (i = 0; i < n; i++)

            sum += foo (i);

        return sum;

    }

}

The space complexity of the above function is:

asked in Asymptotic worst case time and space complexity by gate

1 Answer

0 votes
Note that the function foo() is recursive. Space complexity is O(n) as there can be at most O(n) active functions (function call frames) at a time.
answered by gate

Related questions

The best answer to any question