0% found this document useful (0 votes)
49 views3 pages

Fibonacci Series Assignment

Umm e Aimen submitted assignment 1 to Prof Danish Kaleem with roll number CS-21-20. The assignment discusses the Fibonacci series, a Python program to generate Fibonacci numbers recursively, and analyzes the time complexity. The Fibonacci series begins with 0 and 1, with each subsequent number equal to the sum of the previous two. The Python program defines a recursive Fibonacci function that returns the sum of Fibonacci(n-1) and Fibonacci(n-2). The worst, best, and average case time complexities of the recursive Fibonacci program are exponential O(2^n), constant O(1), and exponential O(2^n), respectively, due to redundant recursive calls.

Uploaded by

Haleema Sajid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views3 pages

Fibonacci Series Assignment

Umm e Aimen submitted assignment 1 to Prof Danish Kaleem with roll number CS-21-20. The assignment discusses the Fibonacci series, a Python program to generate Fibonacci numbers recursively, and analyzes the time complexity. The Fibonacci series begins with 0 and 1, with each subsequent number equal to the sum of the previous two. The Python program defines a recursive Fibonacci function that returns the sum of Fibonacci(n-1) and Fibonacci(n-2). The worst, best, and average case time complexities of the recursive Fibonacci program are exponential O(2^n), constant O(1), and exponential O(2^n), respectively, due to redundant recursive calls.

Uploaded by

Haleema Sajid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment No 1

Name:
Umm e Aimen
Submitted To:
Prof Danish Kaleem
Roll No:
CS-21-20

Fibonacci Series:-
The Fibonacci series is a sequence of numbers in
which each number is the sum of the two preceding
numbers. The series starts with 0 and 1, and the next
number in the sequence is the sum of the previous two
numbers.
The first few numbers in the Fibonacci series are:0, 1, 1,
2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …

Python Program:-
Def Fibonacci (n)
N1,n2=0,1
If n<=0:
Print (“enter number greater than 0”)
Else
Print(Fibonacci (n-1)+ Fibonacci (n-2))

Complexity Analysis:-
 Worst Case:-
The worst-case scenario for this
implementation is when we call the Fibonacci()
function with a large value of n. Since this
implementation uses recursion, the function will keep
calling itself until it reaches the base cases of n=0 and
n=1. This can result in a large number of function calls
and can be very slow, making the worst-case time
complexity exponential, O(2^n), because the number
of function calls grows exponentially with n.

 Best Case:-
In the best case , when n is 0 or 1, the
function returns the value of n itself without making
any recursive calls. This makes the best-case time
complexity constant, O(1)

 Average Case:-
The average-case time complexity of
generating the Fibonacci sequence using a recursive
function is also exponential, which means that the
function runs in a reasonable amount of time for small
input sizes but becomes slow for large input sizes. The
average-case time complexity can be expressed as
O(2^n) as well because the function generates the same
values multiple times, leading to redundant
computations.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy