Sitemap

Recursion

Apr 7, 2022

Recursive functions are functions that invoke themselves. Look at this example:

Python maintains a stack that tells the program which steps to perform. Every time a function is called it is pushed onto the stack, when the function returns or terminates it is popped off the stack. Python keeps the name of the function and the line on which it was called on the stack, so it can go back to the previous point and continue executing code.

Get João Lima’s stories in your inbox

Join Medium for free to get updates from this writer.

Recursive functions use this mechanism to be able to return information to themselves.

Giving some algorithms examples that uses recursion

Fibonacci Sequence

Quicksort

Tower of hanoi

References

Think in python

Grokking Algorithms: An illustrated Guide for Programmers and Other Curious People

--

--