time complexity of reversing a stack using recursion
Time complexity issue
Hi @Rj.25
We are using two functions in which first function is calling itself recursively as well as the second function in each call. Also the second function is calling itself recursively, so Time complexity is O(n ^ 2).
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.
also tell the space complexity of stack reverse using recursion?
space complexity is O(n). this is space used by recursion stack. the space utilized by recursion is max recursion stack depth which is O(n) in this case.
thanks
please rate and resolve if satisfied.
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.