Any looping problem can be solved using recursion is it true? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Any looping problem can be solved using recursion is it true?

21st Jan 2022, 8:04 AM
Piyush Srivastava
Piyush Srivastava - avatar
1 Answer
+ 2
Yes (almost...). One important difference is that some problems are *much* easier to solve using recursion as opposed to looping, and vice-versa. However, recursive solutions have one limitation that loops don't suffer from, the stack size. You can easily overflow the stack with a deep recursion (how deep depends on the actual function, and the stack size, which in-turn (the stack size) depends on the Operating System and configuration), which is something to consider when writing recursive solutions. Though, practically this isn't really an issue, unless if there is a bug in the code, it's something to keep in mind. (this is why i said 'almost...')
24th Jan 2022, 6:57 PM
Isho
Isho - avatar