1. Let us derive the recurrence equation for Fibonnocci series and perform complexity analysis for the same.
The fibonacci numbers are given by the series:
0, 1, 1, 2, 3, 5, 8
defined by the simple recurrence (i.e.)
F(n) = F(n-l) + F(n-2) for n > 1 ….(1)
and two initial conditions are F(0) = 0 F(1) = 1
The nth Fibonacci number is generated by three different ways.
1. Explicit formula
2. Recursive Algorithm
3. Non Recursive Algorithm
1. Explicit Formula
The equation (1) is of the form homogeneous second-order linear recurrence with constant coefficients.
ax(n) + bx(n – 1) + cx(n-2) = 0 …..(2)
The characteristic equation for recurrence in equation (2) is
ar2 + br + c = 0
Apply this theorem to solve Fibonacci numbers
F(n) – F(n-1) – F(n-2) = 0
Its characteristic equation is
r 2- r – 1 = 0
Where a = 1, b = c = -1
are the two roots of the equation.
The roots are real and distinct
To solve & , take initial conditions F(0) = 0 F(l) = 1
Substitute = –
Substitute and in F(n)
Substitute and in F(n)
This is the explicit formula for the nth Fibonacci Number
Note: is known as golden ratio
2. Recursive algorithm
The cognitive algorithm for computing F(n) is given below:
Algoirthm F(n)
// Computes the nth Fibonacci number recursively by using its definition
// Input: A nonnegative integer n
// Output: The nth Fibonacci number
if n > 1 return n
else return F(n-l) + F(n-2)
Analysis
• Input size is equivalent to the given element n.
• Basic operation: number of additions performed to compute F(n-1) and F(n-2) and adding the two terms.
• The recurrence relation is A(n) = A(n-1) + A(n-2) + 1 for n > 1,
A(0) = 0, A(l) = 0
A(n) – A(n-1) – A(n-2) = 1
This is 2nd order in homogeneous recurrence with constant coefficients. To convert this into homogeneous type, add and subtract 1.
[A(n) +1] – [A(n-1) + 1] – [An-2) + 1] = 0
and substituting B(n) = A(n) + 1:
B(n) – B(n-1) – B(n-2) = 0
B(0) = 1, B(l) = 1 is homogeneous.
This equation can be solved exactly in the same manner as explicit formula for F(n).
is the derived recursive Fibonacci formula.
2. Let us discuss about the necessary steps for analyzing the efficiency of recursive algorithms.
A General Plan for Analyzing Efficiency of Recursive Algorithms
1. Decide on a parameter (or parameters) indicating an input’s size.
2. Identify the algorithm’s basic operation. (As a rule, it is located in its inner-most loop).
3. Check whether the number of times the basic operation is executed depends only on the size of an input. If it also depends on some additional property, the worst-case, average-case, and, if necessary, best-case efficiencies have to be investigated separately.
4. Set up a recurrence relation, with an appropriate initial condition, for the number of times the basic operation is executed.
5. Solve the recurrence or at least ascertain the order of growth of its solution.
Example 1: Computing the factorial function F(n) = n! for an arbitrary non-negative integer n.
n! = 1.2….. (n-1).n = (n–l)! . n for n ≥ 1
Algorithm F(n)
//Computes n! recursively
//Input: A nonnegative integer n
//Output: The value of n!
if n=0 return 1
else return F(n–l) * n
Analysis
• Input size is equivalent to the elements in the array = n
• Basic operation – multiplication
• No additional property
• The recurrence relation is
m(n) = m(n-1) + 1 ….. (1)
Substitute n=n-1, m(n-1) = m(n-2) + 1
Put in equation (1)
m(n) = m(n-2) + 2
assume n = n-2
m(n-2) = m(n-3)+l
Put in equation (1)
m(n) = m(n-3) + 3
assume n=n–3
m(n-3) = m(n-4) + 1
Put in equation (1)
m(n) = m(n- 4) + 4.
At the ith iteration 1 ≤ i ≤ n
m(n) = m(n-i) + i
As per the initial condition n-i = 0 i = n
m(n) = m(0) + n
= 0 + n = n Θ (n)
3. Let us design a non recursive algorithm for computing the product of two n × n matrices and also find the time efficiency of the algorithm.
General Plan for Analyzing Efficiency of Nonrecursive Algorithms
1. Decide on a parameter (or parameters) indicating an input’s size.
2. Identify the algorithm’s basic operation. (As a rule, it is located in its inner-most loop).
3. Check whether the number of times the basic operation is executed depends only on the size of an input. If it also depends on some additional property, the worst-case, average-case, and, if necessary, best-case efficiencies have to be investigated separately.
4. Set up a sum expressing the number of times the algorithm’s basic operation is executed.
5. Using standard formulas and rules of sum manipulation, either find a closed-form formula for the count or, at the very least, establish its order of growth.
Given two n-by-n matrices A and B, find the time efficiency of the definition-based algorithm for computing their product C=AB.
Algorithm MatrixMultiplication(A[0…n–1,0…n–1 ],B[0…n–1,0…n–1 ])
//Multiplies two n-by-n matrices by the definition-based algorithm
//Input: Two n-by-n matrices A and B
//Output: Matrix C = AB
for i ← 0 to n – 1 do
for j ← 0 to n – 1 do
C[i,j] ← 0.0
for k ← 0 to n – 1 do
C[i,j] ← C[i,j]+A[i,k]×B[k,j]
return C
Analysis
• Input size is equivalent to the order of the matrix
• Basic operation – Innermost loop operation (i.e.) multiplication.
• No additional property
Essay: Derive the recurrence equation for Fibonnocci series and perform complexity analysis for the same
Essay details and download:
- Subject area(s): Information technology essays
- Reading time: 4 minutes
- Price: Free download
- Published: 27 December 2019*
- Last Modified: 22 July 2024
- File format: Text
- Words: 835 (approx)
- Number of pages: 4 (approx)
Text preview of this essay:
This page of the essay has 835 words.
About this essay:
If you use part of this page in your own work, you need to provide a citation, as follows:
Essay Sauce, Derive the recurrence equation for Fibonnocci series and perform complexity analysis for the same. Available from:<https://www.essaysauce.com/information-technology-essays/derive-the-recurrence-equation-for-fibonnocci-series-and-perform-complexity-analysis-for-the-same/> [Accessed 14-04-26].
These Information technology essays have been submitted to us by students in order to help you with your studies.
* This essay may have been previously published on EssaySauce.com and/or Essay.uk.com at an earlier date than indicated.