+ 2

What is the importance of recursions in c language and why we do use it instead of calling a normal function

Please any answers would help to understand it

6th Feb 2020, 9:58 PM
Amal Gil
Amal Gil - avatar
2 Réponses
+ 8
Recursion and loops are interchangable. Every loop can be coded with recursion and every recursion can be coded with a loop. Depending on the algorithm, one will be easier to understand (assuming recursion and loops are tools you can easily use) so should be the one you code. Given that both are similar, always pick the loop as the stack frame creation/deletion is expensive. You should write a few programs without any loops (recursion instead) to make sure it becomes a strong tool for your future.
6th Feb 2020, 11:59 PM
John Wells
John Wells - avatar
+ 2
Some problems like factorials seem natural to be implemented via recursion because of mathematical facts/formulas like: n! = n*(n-1)!
7th Feb 2020, 2:23 AM
Sonic
Sonic - avatar