Doubt in space complexity @ 2:23

Doubt–while calculating the space complexity of recursive factorial n=1 and n=0 will also be passed as parameter so shouldnt they also be a part of call stack ? They should also occupy space ,shouldnt they

Please mention the name of the video which you are referring too…

LP-Nov Live Session -21

Watched the video at this time stamp, insertion sort was being discussed. Ask me a general doubt, will answer it.

are they passed as an argument or they are being initialized in a function? if initialized then they will occupy a space , they won’t occupy space unless and until they are being passed by reference

Also if your doubt is not clear, then please specify it , will answer that accordingly.

doubt in space complexity @ 2:23:00

Yes they will occupy space each time when fib(2) will be calculated


                          fib(5)   
                     /                \
               fib(4)                fib(3)   
             /        \              /       \ 
         fib(3)      fib(2)         fib(2)   fib(1)
        /    \       /    \        /      \
  fib(2)   fib(1)  fib(1) fib(0) fib(1) fib(0)
  /     \
fib(1) fib(0)

*So Extra Space will be * O(n) if we consider the function call stack size, otherwise O(1).
it’s not shown in the stack as in base case we are returning when n ==1 or 0
return n , nothing else.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.