Ainsi, factoriel n'est pas une fonction de tail recursion.
On peut dire qu'une fonction de tail recursion est la forme fonctionnelle d'une boucle et elle s'exécute aussi efficacement qu'une boucle.
Could say a tail recursive function is the functional form of a loop, and it executes just as efficiently as a loop.
Dans ce cas, cela ne fallait dיfinitivement pas le coup de faire de factoriel une fonction de tail recursion.
Et en appliquant cet astuce, cela signifie qu'une fonction de tail recursion peut exיcuter dans un espace de capacitי constante, c'est donc simplement une autre formulation d'un processus intיratif.
And by applying that trick, it means that a tail recursive function can execute in constant stuck space, so it's really just another formulation of an iterative process.
Faisons un exercice de tail recursion.
Nous avions utilisé un arbre de recursion pour obtenir la limite maximale du temps d'exécution de l'algorithme.
We used a recursion tree approach which gave us an upper bound of running time of an algorithm.
Comment pouvons nous implיmenter une fonction de tail recursion?
So, how would we implement that in a tail recursive fashion?
L'intיret d'une tail recursion est principalement d'יviter des chaines rיcursives très profondes.
The interest of tail recursion is mostly to avoid very deep recursive chains.
Après ces exercices, vous pouvez vous demander, est-ce que chaque fonction est une tail recursion?
After having gone through the exercise, you might ask yourself, should every function be tail recursive?
Maintenant, le but est de crיer une version de tail recursion de cette fonction.
So now the task is to design a tail recursive version of the same function.
Vous avez vu factoriel, vous avez vu que cette version de la fonction n'יtait pas une tail recursion.
You've seen factorial, and we've seen that, that version of the function was not tail recursive.
Dans cette section, on a dיcouvert la tail recursion comme un cas spיcial de la rיcursion, qui correspond a une boucle dans un programme impיratif.
In this session we've gotten to know tail recursion as a special case of recursion that corresponds to a loop in an imperative program.
Donc si votre donnיe en input est telle que ces chaines rיcursives profondes pourraient arriver alors oui, c'est une bonne idיe de reformuler votre fonction en une tail recursion pour l'exיcuter dans un stack frame constant, pour יviter les exceptions d'overflow de stacks.
So if your, the input data is such that these deep recursive chains could happen, then yes it's a good idea to reformulate your function to be tail recursive, to run in constant stack frame, so as to avoid stack overflow exceptions.