CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 2 of 2

Thread: fibrec

  1. #1
    Join Date
    Mar 2012
    Posts
    2

    Unhappy fibrec

    How do i prove this?

    The recursive function fibrec(n) (from the week one lecture notes) has been modified to print the letter t followed by the value of its argument n each time it is called:
    fibrec(n)
    print “t”n
    if n < 2 then return n
    else return fibrec(n-1) + fibrec(n-2)
    Let t(n,x) denote the total number of times the letter t will be printed followed by the number x, during the evaluation of fibrec(n). For example: t3 will be printed twice during the evaluation of fibrec(5), so t(5,3) = 2.
    Prove that t(n,x) is equal to the Fibonacci number fn-x+1 whenever 1 ≤ x ≤ n.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    1,850

    Re: fibrec

    I think a proof by induction would be easiest. You can either start at x = 0 or at x = n.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

+ Reply to Thread

Bookmarks

Posting Permissions

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



HTML5 Development Center

Click Here to Expand Forum to Full Width