Some more tail recursion... →
• algorithms, recursion, ocaml
Let’s continue with tail recursion and folding (recollect our previous post. Let’s use those concepts to write insertion sort algorithm. In an earlier post we wrote a recursive implementation of insertion sort algorithm as below:
Now, let’s write a tail recursive version of insertion sort. Let’s just call it tr_isort
.
Food for thought - is it possible to write a tail-recursive version of insert
function that we used above? If yes, why don’t we try it. If no, why not?