trial recursion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tamara omar
    New Member
    • Sep 2006
    • 23

    trial recursion

    as i know that the memory of each recursive call is stored in a stack, so making many recursive calls may cause a stack overflow problem ,my question is what happens if we call factorial(5) and factorial (1000)?
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    It depends on how your function is defined. I imagine factorial(5) wouldn't have too big a problem, but factorial(1000) may be too big, depending on the computer you're using and the function definition.

    Comment

    • tavianator
      New Member
      • Dec 2006
      • 38

      #3
      factorial(1000) may overflow your stack if it is defined recursively; furthermore, 1000 factorial is too big for even a 64-bit integer. However, factorial can be defined with a for loop, rather than recursion.

      Comment

      Working...