0
When does recursion become useful?
Is recursion useful and when?
5 Respostas
+ 9
When it is used correctly, it is really powerful. But any task done with recursive approach can either way be realized with loops and if conditions.
Recursive approach most often makes the code shorter and easier to maintain (if you know what you are doing), but in general it is memory-intensive (the whole self-revolving algorithm is recurrently calculated in the memory until it reaches the final condition, the base case).
+ 8
Max yes they can 😉 https://gist.github.com/m1el/7fb089e87dae63c7ee5c
+ 5
Max I was rather comparing solutions to tasks - if some task is doable with a recursive approach, it surely is also solvable by using a non-recursive approach.
We are of course not taking into account the primitive recursive functions of mathematical operators, like addition, division, factorial or exponential (or their combinations), which are irreplaceable by definition.
+ 2
Kuba Siekierzyński not all recusive functions can be defined non recursively using loops and if conditions, just look at the ackerman function
+ 1
Quick sort or depth first traversal of trees