Reputation: 372
All problems that are solvable with recursion are solvable with loop, and vice versa.
Is this statement right or proven at all? sometimes, using recursion causes stack overflow. if the statement is correct. we'd better use loop instead.
thanks
Upvotes: 8
Views: 625
Reputation: 361362
Yes. Loop + Stack will solve all recursion problems.
After all, compiler does that internally. Recursion is nothing but pushing data onto a stack, and later popping from it, done by the compiler.
Upvotes: 13
Reputation: 399803
Typically, the corresponding iterative (looping) solution will need just as much storage, but will need to manage it explicitly.
Upvotes: 2