1

I have the following recursive algorithm:

void print(int &N){
    If(N==0)
        return;
    cout << N << " ";
    N = N-1
    print(N);
}

On each recursive step, the function goes on top of the call stack.
When the value of input variable reaches 1, there are N functions in the call stack.
So, what is the space complexity for the algorithm? And in general should we consider the number of elements in Call-stack while calculating space complexity?

Atulya Jha
  • 153
  • 1
  • 2
  • 10

0 Answers0