Question d’entretien chez X

Create an iterative version of a recursive algorithm that uses as little extra space as possible.

Réponse à la question d'entretien

Utilisateur anonyme

5 janv. 2012

Depending on the recursive algorithm you can do a few things. For something simple like Fib or Factorial, you can usually just write a loop instead - this would use no extra space and likely be faster due to no function call overhead compare to the recursive function. If the recursive algorithm is more complex, you can usually simulate how recursion works by creating a stack data structure to push the updated values in each time around the loop.

2