in Programming in C
707 views
1 vote
1 vote
Every recursive program uses strictly more stack space compared to its iterative equivalent.

This statement is false. Please explain with examples
in Programming in C
707 views

2 Comments

It is totally dependent on the Implementation.
0
0
can you explain it more accurately?
0
0

2 Answers

1 vote
1 vote
My approach: Take inorder traversal of a binary tree. You'll need a custom stack if you want to implement the function with iterative version. On comparing this iterative version with recursive version of the inorder traversal, we find that both methods are using same number of stack frames. Recursive version is just easy and more intuitive.

3 Comments

Can iterative version can ever take more stack space than recursive counterpart?
0
0
No, if implemented properly.
0
0

@neeraj33negi

Kindly elaborate with an example..

0
0
0 votes
0 votes
How can iterative algorithm uses more space than it's equivalent recursive algorithm??? Even though both needs variable and program memory but recursive algorithm requires additional memory for stack.

Related questions