0
What's on your computer's mind of a recursion
if use recursion to calculate like 2^n, it takes hell lot time, but if using "if else" ,it will work properly. how cyber brains comprehend a recursion ? For mine, they're likely the same. https://code.sololearn.com/cDU1Rr11Xmdt/?ref=app
1 ответ
+ 7
Recursion is barely an efficient algorithm. It is extremely memory-consuming, as it has to store and remember every step of the recursion (incrementally) until the final, base case, when it starts folding back.
Loops (iterations) on the other hand, recalculate and overwrite everything in each step, so only the current value is stored. It is of course much quicker.
Still, recursion may be a good choice if the memory is not a problem, as it is relatively shorter and faster to code.
EDIT: if you want to know what's on computer's mind when doing the recursion, try this link and see how it might feel like:
https://www.sololearn.com/Discuss/307407/?ref=app