+ 3

Why recursion is needed in c++

8th Jul 2016, 6:59 PM
Prateek panda
Prateek panda - avatar
5 Respostas
+ 3
recursion has many advantages 1) it shortens code 2) it simplifies code ( in more understandable form) 3)it solves many issues of memory and time management
17th Jul 2016, 3:28 PM
manish rawat
manish rawat - avatar
+ 1
Recursion is not needed in a sense that some things can only be expressed via recursion that cannot be expressed by other constructs (there's a proof in theoretical computer science that a recursive function can be transformed to an equivalent non-recursive). Anyways, recursion is often an elegant and short way of handling "recursive" data structures as trees (or in general all data structures that model a whole-part relationship). It's kinda hard to get into at first but it's worth it.
8th Jul 2016, 7:53 PM
Stefan
Stefan - avatar
0
I disagree on the memory and time management part. Just because it's local variables doesn't mean the program has to allocate memory and to be honest a recursive solution is slower just due to the function call overhead and the allocation and freeing of memory. Apart from that, a function calling itself makes it oftentimes as hard to understand as usual sequential code. I give it the elegance and shortness award, though.
17th Jul 2016, 3:39 PM
Stefan
Stefan - avatar
0
Stefan ya i am sorry i just casually wrote memory there, actually u r right , recursion eats memory but it saves time in a sense
10th Dec 2016, 7:09 PM
manish rawat
manish rawat - avatar
0
It might save programming time. As long as the performance overhead does not become too costly due to the inefficiencies of recursion, the programming time is the most costly thing.
10th Dec 2016, 11:33 PM
Stefan
Stefan - avatar