Recursion Help (I don't get this)

I feel so stupid. I just can't understand recursion.
     public static int fib(int n)
          int result;
          if (n <=2)
               result = 1;
          else
               result = fib(n-1) + fib(n-2);
          return result;
     }The above is the famous Fibonacci method. But I DON'T GET IT. How the heck does this work? I don't understand how the recursive case works (result = fib(n-1) + fib(n-2)).
The way I understand it:
If we were to call call fib(5)...
recursive case:
result = fib(n-1) + fib(n-2); -> 4 + 3
The result would be 7, and then we would be done because we've reached the base case (n <=2). The correct answer is 5, so I'm obviously wrong. I just can't grasp this key concept. I'm feeling very noobish. :(

I should add that recursion is related to
mathematical induction, a powerful tool in
mathematics.
And once you get used to thinking about recursion,
you should see that in many ways recursive solutions
are simpler and clearer than non-recursive approaches.Ever so true but an efficient recursive solution should use a stack of
depth log(n), where n is the problem size, at most. It should also not
recompute what has been computed before.
The naive recursive fibonacci function doesn't fit that bill: it uses a stack
of size n for the calculation of fib(n) and it recalculates what has been
calculated before many times.
kind regards,
Jos

Similar Messages

  • I have adobe CS 5.1 and recently (after an update) it is giving me an error (Could not save...because of a program error) every time I try to save my work as a PDF   Help how can I get this resolved??

    I have adobe CS 5.1 and recently (after an update) it is giving me an error (Could not save...because of a program error) every time I try to save my work as a PDF>  Help how can I get this resolved??

    Run the cleaner, reinstall.
    Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6
    And don't bother with running any updates unless you really need them or they fix a critical issue relevant to your workflow.
    Mylenium

  • User sees different version of app than I do. I don't get this.

    I'm developing a web app. I've asked a user to test it out some but she is seeing an older version than I'm seeing apparently. Since I only have one version deployed on Tomcat 5, how can my user see a different-looking JSP on the screen than I do? I'm baffled. This is true day aftter day, no matter how many times both of us close our browsers and no matter how many times I restart tomcat and redeploy my application. I don't get this. What's going on?

    The User Agent supplied with your post (used to identify the browser you are using) shows Firefox 3.0.11:
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 '''''Firefox/3.0.11''''' (.NET CLR 3.5.30729) FBSMTWB
    See http://kb.mozillazine.org/Resetting_your_useragent_string_to_its_compiled-in_default
    See also [http://en.wikipedia.org/wiki/User_Agent User Agent (Wikipedia)]
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    The problem could be caused by that "FBSMTWB" at the end of your User Agent
    *http://www.fastbrowsersearch.com/FBS_Toolbar/Help/helpUninstalling.aspx
    *http://www.pccybertek.com/2009/05/remove-fast-browser-search
    *http://forums.mozillazine.org/viewtopic.php?f=38&t=1430845
    *http://forums.spybot.info/showthread.php?t=51697 - Manual Removal Guide for FastBrowserSearchToolbar
    Not related to your question, but...
    You need to update some plug-ins:
    *Plug-in check: https://www-trunk.stage.mozilla.com/en-US/plugincheck/
    *Adobe Shockwave for Director Netscape plug-in: [https://support.mozilla.com/en-US/kb/Using%20the%20Shockwave%20plugin%20with%20Firefox#w_installing-shockwave Installing ('''''or Updating''''') the Shockwave plugin with Firefox]

  • The problems seems that the free trial what i am constantly paying for may have ran out/free trial time never contacted as i find this online to take to long and to hard to deal with  yet a paying costumer restricted by some weird fault i don't get this t

    the problems seems that the free trial what i am constantly paying for may have ran out/free trial time never contacted as i find this online to take to long and to hard to deal with  yet a paying costumer restricted by some weird fault i don't get this tried every thing how can i be billed and money taken for hired subscription  but end up with a "free trial" that cut me off having withdrawal as i live my life inside Photoshop 

    Use the trackpad to scroll, thats what it was designed for. The scroll bars automatically disappear when not being used and will appear if you scroll up or down using the trackpad.
    This is a user-to-user forum and most people will post on here if they have problems. You very rarely get people posting to say there update went smooth. The fact is the vast majority of Mountain Lion users will not be experiencing any major problems with the OS, or maybe with apps which are not compatible, but thats hardly Apple's fault if developers don't update their apps.

  • Help! I am getting this error message in Premiere Pro 4

    Help! I am getting this error message in Premiere Pro 4
    [/belding/mediaCore/MediaLayer/AudioSupport/Make/Mac.../.../src/Mac/CoreAudioHost.ccp-1623
    Does anyone know what this means?
    I am using a very new IMac and running the latest apple os
    Thank you

    answer probably here
    http://forums.adobe.com/message/1826019

  • Barcode shows a bunch of squares when barcode is made on AI CS11. Does anyone know a fix for this? We have CS2 running on another PC and we don't get this problem.

    Barcode shows a bunch of squares when barcode is made on AI CS11. Does anyone know a fix for this? We have CS2 running on another PC and we don't get this problem.
    Background:
      Using FrameMaker 7.1 to create a PDF file where a CS11 barcode file is embedded. PDF generates fine but we get a bunch of squares when we copy and paste the barcode data into Notepad.
      We have CS 2 running on another PC and we don't get this problem. Do I need to install a plugin (if any) for CS11 to get this to work?
    Thanks!

    Thanks for your feedback.  I was not able to mention earlier that in my line of work, we use Notepad to check if the barcode text is written correctly or if the corresponding text can be found if searched in the PDF... We use FREE3OF9.TTF font when entering text values for the barcode (usually in document/part number format exclusive for our company's use) in AI CS11. After saving the AI file, we attach it in a document using FrameMaker 7.1, then a PDF file is created. The output PDF will be a certification sheet for our products. They (our clients) should be able to scan the document/part number out of the barcode. I'm sorry, I could not divulge any other information so I am not sure if this clears out the issue. It used to work before but I had to get my PC formatted and since then I have been encountering this problem. I am trying to figure out if we missed to install a component or something got messed up after re-installing Adobe Illustrator CS11.

  • Just had help installing cc 2014. get this dialog box when i open the app. One or more files in the adobe folder necessary for running photoshop are missing. Help

    Just had help installing cc 2014. get this dialog box when i open the app. One or more files in the adobe folder necessary for running photoshop are missing. Help

    Please Run the Cleaner tool to remove Ps CC 2014 :http://www.adobe.com/support/contact/cscleanertool.html .
    Restart your system and then try installing Ps CC 2014 again.
    Regards,
    Ashutosh

  • 'Audio configuration Damaged' Help! I keep getting this message and losing songs :( Any ideas?

    I seem to be getting this a lot lately and I've lost work, anybody got any ideas how to stop/overcome this?

    This message appears after start up and after the HP help and support bar appears
    Unhandld exceptions has occured in your application. If check continue, the application willignore this errorand attempt to continue.  If you check quit the application will close immediately.
    c:\ProgramDataHewlettPackard\HPHelpupdater\ehelpin​stallOEM\Misc.
    I have opened msconfig and this dialog does not appear

  • HT3275 Can anybody help me. I get this message when am trying to do my backup:The backup disk image "/Volumes/Data/Anne Prybyla's iMac.sparsebundle" is already in use.

    When i try to use time Machine for my backup i get this message: The backup disk image "volume/data/AnnePrybyla's imac.sparsebundle is already in use. What can i do

    Look over to the right of this page under the heading of More Like This for multiple answers and solutions to this bug.

  • HELP!  I keep getting this message "network connection could not be established."

    I just updated my iPhone 3GS but when I try it with my iPad 2, I keep getting this message, "There was a problem downloading the software for the "iPad".  The network connection could not be established.  Can anyone please tell me what to do?  Thanks.

    Cheryl and Hmariepugh-
    The problem may be at Apple's end due to the large number of people trying to update at the same time.  I suggest you keep trying.  Perhaps it will be easier during early morning hours U.S. time, before 10 AM GMT.
    Fred

  • I don't get this. . .  .help

    Anybody know why Toast will start to extract a video from my iDVD disk and then say, "I/O error - your disk may be copyrighted? Very frustrating.. . thanks. . . Jim

    I should add that recursion is related to
    mathematical induction, a powerful tool in
    mathematics.
    And once you get used to thinking about recursion,
    you should see that in many ways recursive solutions
    are simpler and clearer than non-recursive approaches.Ever so true but an efficient recursive solution should use a stack of
    depth log(n), where n is the problem size, at most. It should also not
    recompute what has been computed before.
    The naive recursive fibonacci function doesn't fit that bill: it uses a stack
    of size n for the calculation of fib(n) and it recalculates what has been
    calculated before many times.
    kind regards,
    Jos

  • Please Help!  Need to get this done soon - Bigger Size slideshow on web

    Hello,
    I need to publish on the web a slideshow of some of my pics, but I need to publish them at a size much bigger than the little iMovie screen size I have now with iLife 06 and .Mac (the little screens that looks like a movie screen and other designs - I think it is at 320X240). I will go buy iLife 08 today if it will allow me to do what I want to do which is publish a slideshow with music of my photos at 640X480 or *preferably even bigger*. Can I do that with iLife 08 and how?

    Have you considered using iWeb to create a photo page and slideshow? It creates slides that are 800 x 600 pixels in size for the slideshow. Here's an example of such a photo page/slideshow.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Please help me out in getting this information.....

    *1) The name of the Cookie*
    *2) The value*
    *3) The directory path*
    *4) The size of the cookie ie. 1024 bytes*
    After that I am unable to make out , what are the rest of the informations
    Can any one help in understanding what are all information which gets stored in the text file apart from the 4 mentioned one.
    regards,

    Look under "cookie attributes" here.
    - Saish

  • Honestly, I don't get this camera..

    I have a Nikon D80 and I have been known to take some amazing shots since I have had it, but with my iPhone, all I get are super grainy, super blurry pics.
    What I do is point the camera at the subject...click and hold the camera button, wait for the image to stop "waving" around, and release.
    The camera will "click" and the fake shutter thing will go, but then my photo is full of motion blur.
    It's almost like the shutter speed isn't quick enough to eliminate shaky hands or subject movement. Is there anything I can do to take better photos as I have seen some other threads on other forums of people taking some pretty ok ones from the back of speeding boats, of pets, of storms...
    Thanks,
    Jeff

    I'm noticing that the fake shutter doesn't seem like the "cut off" point for the photo. If you click the button and the shutter is moving, you can actually blur the pic during this time.
    Perhaps someone can test this out. If this is the case they should change it so the photo is taken the second you release the button as it's a tad confusing to have it still be taking a photo during that time.
    It really should work like other cameras though...where when you click the button it takes a photo...not when you release the button, that just doesn't make any sense.

  • Help! i keep getting this message on startup

    during startup, the HP help and support hangs up and then gives the following error. Please tell me what i need to do to fix this annoying problem
    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.
    ************** Exception Text **************
    System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\ProgramData\Hewlett-Packard\HPHelpUpdater\eHel​pInstallOEM\Misc'.
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.Directory.InternalGetFileDirectoryNames(​String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption)
       at System.IO.Directory.GetDirectories(String path, String searchPattern, SearchOption searchOption)
       at System.IO.Directory.GetDirectories(String path)
       at HPHelpUpdater.mainModule.restoreFolder(String backupFolder, Boolean rollback)
       at HPHelpUpdater.mainModule.restoreBackedupFiles(Bool​ean rollback)
       at HPHelpUpdater.mainModule.main()
       at HPHelpUpdater.statusForm.Timer1_Tick(Object sender, EventArgs e)
       at System.Windows.Forms.Timer.OnTick(EventArgs e)
       at System.Windows.Forms.Timer.TimerNativeWindow.WndPr​oc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.​50727/mscorlib.dll
    HPHelpUpdater
        Assembly Version: 1.4.2.0
        Win32 Version: 1.4.2.0
        CodeBase: file:///C:/Users/Doug/AppData/Local/Temp/HPHelpUpd​ater.exe
    Microsoft.VisualBasic
        Assembly Version: 8.0.0.0
        Win32 Version: 8.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.Vis​ualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.Visua​...
    System
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.​0__b77a5c561934e089/System.dll
    System.Windows.Forms
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Window​s.Forms/2.0.0.0__b77a5c561934e089/System.Windows.F​...
    System.Drawing
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawin​g/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    System.Runtime.Remoting
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtim​e.Remoting/2.0.0.0__b77a5c561934e089/System.Runtim​...
    Accessibility
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Accessibility​/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
    System.Management
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Manage​ment/2.0.0.0__b03f5f7f11d50a3a/System.Management.d​...
    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.
    For example:
    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>
    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.

    This message appears after start up and after the HP help and support bar appears
    Unhandld exceptions has occured in your application. If check continue, the application willignore this errorand attempt to continue.  If you check quit the application will close immediately.
    c:\ProgramDataHewlettPackard\HPHelpupdater\ehelpin​stallOEM\Misc.
    I have opened msconfig and this dialog does not appear

Maybe you are looking for

  • TS3989 How do I view my photo stream from ipad and iphone on icloud?

    I have icloud on but it does not show my photos or photo stream when I log into icloud on my PC.

  • Lightroom shows "no photo selected" after editing jpg in Photoshop

    I am running Lightroom 5.3 and Photoshop 14.2.1x64 on Windows 7, 64-bit, 16gb RAM, plenty of free disk space (90gb on drive C).  I am in Lightroom and have selected a subset of the library (using a key word clicking on the keyword's "right arrow" nex

  • Business Group Contacts

    Hi Guys, As the admin of our group account, i would like to create new users and pre-populate their contact list with all of the other contacts within our Skype group. It would also be cool if any new users i create have their details passed on autom

  • Creative suite 6 downloads only fonts

    I purchased creative suite 6 design standard and have tried downloading the programs several times. After hours of waiting, a icon of a purple cd comes up for indesign with "contents" under it and an orange one for illustrator with "Adobe Illustrator

  • Importing Outlook Express email address book

    I have tried to sync my email address book but nothing gets transferred. What do I have to do?