+ 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
2 ответов
+ 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.
+ 2
Some problems like factorials seem natural to be implemented via recursion because of mathematical facts/formulas like: n! = n*(n-1)!