3 ms·
The tail-recursive form is more efficient, but requires a lot more understanding of the problem to follow how one gets from the mathematical definition to the c
by al2o3cr 9y ago
The tail-recursive form is more efficient, but requires a lot more understanding of the problem to follow how one gets from the mathematical definition to the code.
If you're teaching a language that emphasizes tail-call optimization, it's valuable to cover an even simpler case like factorial in detail. A function like "fib2" above is then a further demonstration of how to transform code into tail-call form.