Compare commits

...

2 Commits

2 changed files with 35 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
# Problem Statement: Write a program non-recursive and recursive program to calculate Fibonacci numbers and analyze their time and space complexity.
# Non-recursion
def fibonacci(n):
fib_series = []
a = 0
b = 1
for i in range(n):
fib_series.append(a)
a, b = b, a + b
return fib_series
# Recursion
def fibonacci_recursive(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib_series = fibonacci_recursive(n - 1) # Get the series up to n-1
fib_series.append(fib_series[-1] + fib_series[-2]) # Append the next Fibonacci number
return fib_series
# Non-recursion
n = int(input("Enter total numbers to print in fibonacci series:\t"))
print("Fibonacci Series (non-recusive):\t", fibonacci(n))
# Recursion
print("Fibonacci Series (recusive):\t\t", fibonacci_recursive(n))
+2
View File
@@ -10,6 +10,8 @@ This repository contains valuable resources for the Design and Analysis of Algor
### Codes
1. [Code-A1 - Fibonacci Series](Codes/Code-A1.py)
### Practical
### Question Papers