0
Recursion and iteration who is better
Considering the speed, number of steps and the complexity which system or writing code is ideal or usually suitable in most cases
3 Antworten
+ 11
if you can avoid recursion - do, however as @merkafter said, trees and graphs are mostly handled by recursion and there is no escaping that.
One tip - the moment you start writing a recursion, write your exit condition, then do everything else.
+ 5
Iteration-based solutions are always faster but there are problems which are much easier to solve with recursion.
0
It depends on the problem.
To calculate the fibonacci numbers for example an iterative technique is better while recursion if often better in terms of graphs and trees.