0

When does recursion become useful?

Is recursion useful and when?

29th May 2018, 2:40 PM
Panagiotis Skoulis
Panagiotis Skoulis - avatar
5 Respuestas
+ 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).
29th May 2018, 3:29 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
29th May 2018, 5:21 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 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.
29th May 2018, 5:41 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
Kuba Siekierzyński not all recusive functions can be defined non recursively using loops and if conditions, just look at the ackerman function
29th May 2018, 3:48 PM
Max
Max - avatar
+ 1
Quick sort or depth first traversal of trees
1st Jun 2018, 12:13 AM
Franz
Franz - avatar