Results 1 to 4 of 4

Thread: How Does Recursion Work?

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Answers
    2

    Smile How Does Recursion Work?

    how does stack works when we called a variable storing recursion result


  2. #2
    Expert Member
    Join Date
    Dec 2007
    Answers
    138

    Re: How Does Recursion Work?

    I am not sure but as my view, stack allocated every time in recrusion and stack size is repetitively increase. For your reference you can understand the exact meaning by the program :
    Factorial with recursive and factorial with non recursive implementation


  3. #3
    Junior Member
    Join Date
    May 2008
    Answers
    1

    Re: How Does Recursion Work?

    If we are using a recursive factorial function say FactA()

    and put the result in a variable like

    int I=FactA(5)

    The FactA() will use stact to calculate the factorial and store it in I

    and further in program we use the value of the variable then the value store in I Uses


  4. #4
    Expert Member
    Join Date
    Dec 2007
    Answers
    138

    Re: How Does Recursion Work?

    Hi,
    There are two methods recursive and non recursive : If you use stack in recursive method stack allocated every time in recrusion and stack size is repetitively increase. you its a not good practise,,,,,,, A simple example in performance perspective if you use recusive factorial program with more than 12 number then you should not use recusive method.


  5.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact