Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 96789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:52:50+00:00 2026-05-10T23:52:50+00:00

In the Fibonacci sequence, I have seen conventional implementations which recursively call the same

  • 0

In the Fibonacci sequence, I have seen conventional implementations which recursively call the same method twice:

public void fibonacci(int i) { fibonacci(1) + fibonacci(2); } 

Now this method is not the exact copy of what I have seen or the right way of solving the problem, but I’ve seen the two methods added together like above. So the method isn’t recursively called, but recursively called twice. What exactly happens when writing code like this in C#? Are the two methods run on seperate threads? What is happening under the hood?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:52:51+00:00Added an answer on May 10, 2026 at 11:52 pm

    This is one of those times when it’s useful to think about the way the computer does it.

    Let’s start with the function. I’m going to write it in Python flavored pseudocode because I want you to get away from thinking about the LANGUAGE for a second.

    def fib(n):     if n == 0: return 0     if n == 1: return 1     if n >  1: return fib(n-2) + fib(n-1) 

    Now let’s walk through this for fib(2)

    fib(2) has n>1, so it takes the third branch,

       return fib(2-2) + fib(2-1) 

    so it calls fib() with 0, which is 0

       return 0 + fib(2-1) 

    calls fib() with 1

       return 0 + 1 

    and we see the result 1. Now consider fib(3):

    n>1, so

    return fib(3-2)+fib(3-1) 

    and since 3-2 is 1, we get fib(1) for the first term, which is 1:

    return 1 + fib(3-1) 

    and now when we call fib(3-1), which is to say fib(2), we don’t have the direct answer yet; n>1. So it becomes

    return 1 +     return fib(2-2) + fib(2-1) 

    which becomes

        return 0 + 1 

    ans we pop back to the earlier call

    return 1 + 1 

    and get the value 2. So, you see, there’s no separate thread, it just works its way across the expression. I’ll leave it as an exercise to work out an example for fib(4); I bet if you do, though, you’ll have it nailed.

    Pop quiz: why is the iterative version so dramatically more efficient?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.