Results 1 to 18 of 18

Thread: Recursion

Hybrid View

  1. #1
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Recursion

    I think DDay pointed the way to work it out with pen and paper -- or on screen, in his case. Once your exit condition test is in place, work out the result of the function by hand with starting values of n = 2, 3, 4, 5 and so on. You'll soon notice a pattern in the results!

    I'm assuming you can't start with n negative, by the way.

    BB

  2. #2
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    537

    Re: Recursion

    Hello
    Is this a homework assign?
    I agree with BB you need to start with n=2. f(0)=0 and f(1)=0 by your conditions.
    I do not agree with dday9 as to the values.
    I believe f(2)=-1, f(3)=-2, f(4)=-3, f(5)=0 and so on.
    I wrote code that did not use resursion and believe f(1337)=444
    In my experience dday9 is usually right. So... ?
    George

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Recursion

    EDIT: George was right after all, and I was wrong. Reminder to self: never post opinions about code without testing them first! What I mistakenly wrote was this:

    George, f(2) evaluates to f(2 - 1) - 1 = f(1) - 1. Since evaluation takes place from left to right, f(1) has to be calculated before the 1 can get subtracted; and it never does get subtracted, because evaluating the function f(1) returns 0 and that's the end of it. This kind of thing happens all the time.

    BB

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width