0

I was doing a basic implementation of fibonacci series in python3. Currently I am not thinking about the optimization but the basic output. The case is, the program gets stuck at some point for the value >35 or something.

I really want to know what causing this long calculating time issue?

I have already tried the dynamic programming way, that works fine for larger values too. I have also implemented that in C but no solution. In case of memory storage, it's also not a very big thing to store or process.

def fibonacci_recursive(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fibonacci_recursive(n-1)  + fibonacci_recursive(n-2)

print(fibonacci_recursive(45))

Without showing any kind of error, the program get deeper and deeper of recursion.

Ashraful
  • 59
  • 9
  • 4
    It's not an infinite loop; it just takes a very long time to complete. – chepner Sep 10 '19 at 20:05
  • https://stackoverflow.com/questions/18172257/efficient-calculation-of-fibonacci-series –  Sep 10 '19 at 20:08
  • 2
    Possible duplicate of [Efficient calculation of Fibonacci series](https://stackoverflow.com/questions/18172257/efficient-calculation-of-fibonacci-series) – Patrick Haugh Sep 10 '19 at 20:09
  • Thanks for addressing the duplicate question. Exactly what I needed to know. – Ashraful Sep 10 '19 at 20:12

0 Answers0