Which one to use Iteration or Recursion and Why? -
sorry not exact answer other related questions here.in general, if not know beforehand how many iterations or repetitions may need problem . better solution in of cases , why?
i think decision depends on problem itself. if had no idea number of iterations of algorithm, use recursive algorithms when feel nature of problem helps me that.
for example, if wanted calculate possible non empty subsets given set, use recursive algorithm, , if wanted calculate sum of list of elements, use iterative algorithm.
in both cases use other method solve problem, feel more comfortable coding way.
Comments
Post a Comment