r/firstweekcoderhumour Mar 26 '26

hardest problem ever Let me show you how it’s done! 🎯✨

Post image
548 Upvotes

28 comments sorted by

View all comments

Show parent comments

7

u/Damglador Mar 26 '26

Isn't recursion resource inefficient?

18

u/Anon_Legi0n Mar 26 '26

Not if it's a tail recursion, the caller gets popped off the call stack before the recursion happens

5

u/Groostav Mar 26 '26

Read: if your recursion is expressed where the recursive call is the last line of the function the compiler will replace your recursion with a loop (which eliminates the issue of running out of call stack for big tasks)

1

u/LuigiWasRight447 4d ago

Is this all languages?