Consider the following C-function: double foo (int n){ int i; double sum; if…

GATE · 2005 · CS

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:

  1. A.

    O(1)

  2. B.

    O(n)

  3. C.

    O(n!)

  4. D.

    O(nn)

Attempted by 314 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…