booirror
booirror

Reputation: 372

Are all problems that are solvable with recursion solvable with loop?

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

Answers (2)

Sarfaraz Nawaz
Sarfaraz Nawaz

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

unwind
unwind

Reputation: 399803

Typically, the corresponding iterative (looping) solution will need just as much storage, but will need to manage it explicitly.

Upvotes: 2

Related Questions