Read more stories on Hashnode

Articles with this tag

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...

This article introduces an important concept in recursion: the tail recursion. We see what tail recursion is, and where it is used. Let us get back to the factorial program: def factorial(n): if n == 0: return 1 return n * factorial...