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 8920873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:23:18+00:00 2026-06-15T06:23:18+00:00

I need some help in understanding the processing that happens here, so let´s say

  • 0

I need some help in understanding the processing that happens here, so let´s say I call fib(5) I want the fibonacci 5, which is 8. But my brain in trying to understand the algorithm says it´s not. This is how i (wrongly) think:

return fib(4) + fib(3) // Stack frame 1
return fib(3) + fib(1) // Stack frame 2

now cause x is 1 fib(1), the conditional statement if x == 0 or x == 1: causes the recursion to end. Which according to my logic would become 3+1+4+3. Please correct my faulty logic.

def fib(x):
    """assumes x an int >= 0
       returns Fibonacci of x"""
    assert type(x) == int and x >= 0
    if x == 0 or x == 1:
        return 1
    else:
        return fib(x-1) + fib(x-2)
  • 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. Editorial Team
    Editorial Team
    2026-06-15T06:23:19+00:00Added an answer on June 15, 2026 at 6:23 am

    Here is the full expansion of what happens:

    fib(5) expands to fib(4)+fib(3)
      fib(4) expands to fib(3)+fib(2)
        fib(3) expands to fib(2)+fib(1)
          fib(2) expands to fib(1)+fib(0)
            fib(1) evaluates to 1
            fib(0) evaluates to 1
          fib(1) evaluates to 1
        fib(2) expands to fib(1)+fib(0)
          fib(1) evaluates to 1
          fib(0) evaluates to 1
      fib(3) expands to fib(2)+fib(1)
        fib(2) expands to fib(1)+fib(0)
          fib(1) evaluates to 1
          fib(0) evaluates to 1
        fib(1) evaluates to 1
    

    If you count the ones, you get 8 as the answer.

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

Sidebar

Related Questions

I need some help in understanding what is happening here .I am getting a
I need some help understanding what's happening here. This code is from a models/log.py
I'm new to ORM stuff and I need some help understanding something. Let's assume
Need some help understanding the difference between the success and ajaxSuccess events documented here
Need some help understanding if I'm on the right track here and exactly what
I need some help in understanding my error. I want to read data from
I need some help understanding this bit of code pre { white-space: pre; white-space:
OK, I need some help understanding the process behind Facebook's website integration process and
Oracle's PL/SQL is fairly new to me, so I need some help understanding if
I need some help in understanding when and why to use Remote Service instead

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.