This commit is contained in:
Miloslav Ciz 2022-04-09 20:51:52 +02:00
parent 2a3b06eb67
commit 3abdc93103
17 changed files with 160 additions and 24 deletions

View file

@ -37,4 +37,6 @@ unsigned int factorial(unsigned int x)
}
```
How do the computers practically make recursion happen? Basically they use a [stack](stack.md) to remember states on each level of the recursion. In programming languages that support recursive function calls this is hidden behind the scenes in the form of [call stack](call_stack.md). This is why an infinite recursion causes stack overflow.
How do the computers practically make recursion happen? Basically they use a [stack](stack.md) to remember states on each level of the recursion. In programming languages that support recursive function calls this is hidden behind the scenes in the form of [call stack](call_stack.md). This is why an infinite recursion causes stack overflow.
Another important type of recursion is **tail recursion** which happens when the recursive call in a function is the very last command. It is utilized in functional languages that use recursion instead of loops. This kind of recursion can be optimized by the compiler into basically the same code a loop would produce, so that e.g. stack won't grow tremendously.