Jan-14-2021, 09:50 PM
(Jan-14-2021, 08:33 PM)deanhystad Wrote: dastardly is "evil, wicked, cruel". Recursion is dastardly. The solutions are often far from being efficient or understandable. Recursive solutions often have restrictions that cause them to fail for some data sets while working fine for others (recursion depth). Recursion is difficult to debug.
Sometimes a recursive solution is a good solution, but that is just not the case with an insertion sort.
Recursion depth might be a problem, but only under special circumstances. As I pointed out, recursive solutions are often simple: "how do we take one (more) step towards a solution and how do we know when to stop?"
Also, some problems are natural to solve with recursion and others can not be (easily) solved with iteration. Quicksort, mergesort, depth-first search (like binary tree search) are some examples where recursion is much more efficient than iteration (apart from memory usage). The round-off algorithms for floating number operations are often recursive divide-and-conquer algorithms as they generally provide better results than the iterative ones.
So, even if you don't like recursion and even if recursive solutions sometimes are hard to understand and debug, recursion is important and thus important to study.