Download presentation
Presentation is loading. Please wait.
1
Tail Recursion
2
Iterative Memory Use iterativeFact requires ~12 bytes of storage
Regardless of n
3
Iterative Memory Use recursiveFact requires ~8 bytes of storage
Per function call!!!
4
Limited Space Stack has X amount of space
Deep recursion will run out of memory:
5
Tail Recursion Tail recursive function : One that does no work after recursive call other than return answer Calculates on way in using extra parameter
6
Tail Call Optimization
Compiler can reuse stack frame… only allocate one chunk of memory
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.