Read more stories on Hashnode

Articles with this tag

The best way to learn about recursion is to try a language that doesn't support iteration. Scheme is a good language to learn in this context. It is simple and easy to understand. To experiment with some programs in Scheme, download Dr. Racket from h...

This part deals with two areas for which recursion is commonly applied. The first, called structural recursion, is used to traverse through different parts of a data structure, processing each part in some way. The second, called generative recursion...

This part introduces tree recursion, a form of recursion that occurs when a function calls itself more than once in a path. We then introduce dynamic programming, a class of algorithms to tackle certain types of tree recursive problems. Some recursi...

Try out the following problems: Ask any questions/answers in the comments. Is this tail recursion? def fibonacci(n): if (n <= 2): return 1 return fibonacci(n - 2) + fibonacci(n - 1) What about this? def find_root(node): if node.p...

In the previous post we were looking at tail call optimisation of this factorial implementation def factorial(n): return factorial_acc(1, n) def factorial_acc(acc, n): if (n == 0): return acc return factorial_acc(n * acc, n - 1) ...

In the previous part, we implemented a factorial program using pure tail recursion and accumulators. This was the code def factorial(n): return factorial_acc(1, n) def factorial_acc(acc, n): if (n == 0): return acc return factori...