Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tail Recursion.

Similar presentations


Presentation on theme: "Tail Recursion."— Presentation transcript:

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


Download ppt "Tail Recursion."

Similar presentations


Ads by Google