Simulating Recursion with Generators
I’ve recently had an idea to use generators to define and iteratively execute recursive functions.
Well why would we need to change the recursion to iteration? Because when the recursion runs too deep we can get a stack overflow.
thread 'main' has overflowed its stack fatal runtime error: stack overflow In these cases we normally transform the recursive algorithm to an iterative one by using our own heap stack to simulate the recursion.
[Read More]