Searching tail recursion
on the internet I stumbled on How does compiler know whether the recursion is a tail recursion or not and how does it optimize tail recursion. If I understand correctly then the reason for tail recursion being faster than non-tail recursion is that compliers don't create stack frames for new function calls. Then it is compiler dependent right? Is it always guaranteed on all compilers for all languages? Also, if it is compiler dependent then why do many people keep calling it "algorithm"?
Asked
Active
Viewed 41 times
0

duong_dajgja
- 4,196
- 1
- 38
- 65
-
In some languages (eg scheme) the compiler is required to do tail recursion elimination as part of the language spec. In others it is just an optional optimization. A tail recursive "algorithm" is one which is amenable to (and improved by) this optimization. – Chris Dodd Apr 24 '23 at 03:28
1 Answers
0
Yes, tail-call (recursive or not) optimization is implementation-dependent. And no, if compiler isn't smart enough yet, it won't be able to detect at least some of the tail calls.

DannyNiu
- 1,313
- 8
- 27