Professional Documents
Culture Documents
Complexity Study On Fibonacci New
Complexity Study On Fibonacci New
Complexity Study On Fibonacci New
Abstract
This report deals with algorithmic complexity used in the determination of Fibonacci’s
sequence term. While exposing three correct algorithms, we have, in the light of complexity
study of each one of them, released the one that is optimal. Numbers of Fibonacci’s sequence
being for the majority very large, we preferred the using of computer to determine them.
History
Leonardo Fibonacci first proposed the sequence of numbers named in his honor in his
book Liber Abaci (Book of the Abacus). The rabbit problem was an exercise in addition and not
an attempt to accurately model a rabbit population. It appears that the relation fn = fn+1+ fn+2 was
not recognized by Fibonacci but was first noted by Albert Girard in 1634. In 1844 G. Lame
became the first person to use the Fibonacci numbers in a "practical" application when he used
the Fibonacci sequence to prove the number of divisions needed to find the greatest common
divisor of two positive integers using the Euclidean algorithm does not exceed five times
the number of digits in the smaller of the two integers. 1 The use of the term "Fibonacci
numbers" was initiated by E. Lucas in the 1870's. Many relations among the Fibonacci and
related numbers are due to Lucas and a recurring series first proposed by Lucas has taken his
Another series, that appears later in this thesis, first described by Lucas is:
1.1 Introduction
If we look around us, we see that computers and computer networks are everywhere,
activating a fabric of complex human activities: education, trade, entertainment, research, health,
communication, and even war. One of the two technological factors causing this astonishing
proliferation, is obviously the blowing speed with which the projections in micro-electronics and
design of chips took us to increasingly fast hardware. However, though becoming increasingly
fast, computers do not manage to solve certain problems for which the algorithms are however
The word "algorithm" comes from the Latin word (Algorismus) taken after the name of
on Indian positional decimal calculation (about 830 A.D.) explaining its use and, especially, the
handling of various algorithms that allow to carry out traditional arithmetic operations (addition,
Definition 01 (Algorithm)
Definition 2 (Program)
language (on a given architecture). It is about the implementation of the principle. For example,
during the programming, one will sometimes explicitly deal with the memory management
Time complexity
In computer science, the time complexity is the computational complexity that describes
the amount of time it takes to run an algorithm. Time complexity is commonly estimated by
counting the number of elementary operations performed by the algorithm, supposing that each
elementary operation takes a fixed amount of time to perform. Thus, the amount of time taken
and the number of elementary operations performed by the algorithm are taken to differ by at
most a constant factor. The time complexity is generally expressed as a function of the size of the
input. Since this function is generally difficult to compute exactly, and the running time for small
inputs is usually not consequential, one commonly focuses on the behavior of the complexity
when the input size increases—that is, the asymptotic behavior of the complexity. Therefore, the
time complexity is commonly expressed using big O notation, typically O(1), O(n) , O(log n),
O(2n) etc., where n is the input size in units of bits needed to represent the input. Algorithmic
complexities are classified according to the type of function appearing in the big O notation.
2. Methods of Computation
There are many ways to compute Fibonacci numbers. Each section of this report will
describe one method (and closely related methods) of computing the Fibonacci numbers.
4
numbers. The function fib(n) that computes f(n) will return zero if n = 0, one if n = 1 and the sum
C++ program
if (n<=1) ___________________________________________________ 1
return n;
Time complexity
BIG-O
O (2n)
5
Following fig 2.1 will show the execution of recursive program of finding nth Fibonacci
number. For different values of n. The time is noted in microseconds and three different readings
were taken. Average of three reading show the actual Time complexity of this approach. The
graph represents three readings as well as the average of the recursive function Time complexity.
Fig (2.1)
6
If, instead of first computing f(n-1) and f(n-2) as was done in the recursive solution,each
element of the sequence f0, f1, f2…, fn was computed in order, the number of operations could be
reduced. The algorithm presented in figure 2.2 computes Fibonacci numbers in this manner.
C++ program
return n; ___________________________________________________ 1
else
while(n>=2) _________________________________________________ n
n--;
}
7
Time complexity
T (n) = 4n + 1
BIG-O
O (n)
Following fig 2.2 will show the execution of iterative program of finding nth Fibonacci
number. For different values of n. The time is noted in microseconds and three different readings
were taken. Average of three readings show the actual Time complexity of this approach. The
graph represents three readings as well as the average of the iterative Fibonacci Time
complexity.
8
Fig (2.2)
While the following is usually called Binet's formula for fn, Knuth [19] credits Abraham
1 1 + √5 1 1 − √5
𝑓(𝑛) = ( )− ( )
√5 2 √5 2
C++ program:
Time complexity
BIG-O
O (1)
Following fig 2.3 will show the execution of explicit program of finding nth Fibonacci
number. For different values of n the time is noted in microseconds and three different readings
were taken. Average of three readings show the actual Time complexity of this approach. The
graph represents three readings as well as the average of the explicit Fibonacci Time complexity.
10
Fig (2.3)
11
Even though we have the algorithm, there are three questions that we ask on this subject:
The first question is debatable (it might not be asked) more especially as the algorithm, as
well as the corresponding program, is precisely the Fibonacci’s definition of . But the second
Let T (n) be the number of operations which the computer needs to carry out to calculate
F (n).
What can we say about this function? For not informed readers, if is lower than 2, the
procedure stops almost immediately after two operations. Thus, T(n) ≤ 2,∀ n ≤ 1.
For great values of n, there are two recursive invocations of F (n) repeated T (n-1)and
T(n-2) 2 times respectively, plus three operations of the computer (2 checks on the value of and
Let us compare this result with the recursive relation of fn. We see immediately that. T(n)
≥ fn This is a bad news: The execution time of the algorithm grows as quickly as Fibonacci’s
numbers! T(n) is exponential out of n, which implies that the algorithm is practically slow except
calculate F200, the F (n) algorithm carries out T (n) ≥ F200 ≥ 2138 elementary operations of the
computer. Time that takes depends of course on the computer used. Until 2006, Dasgupta et al.
12
[12, 13] affirm that the fastest computer in the world was the NEC Earth Simulator whose speed
was 40. 10 12 elementary operations per second. Even on this computer, F (n)(200) would take
at least 292 seconds ( 151 x1020 years). This means that, if we begin calculation today, it would
continue even after the sun is transformed into an enormous red star.
phenomenon sometimes called "Moore’s law". With this extraordinary growth, perhaps F (n)
will be carried out more quickly by the future years machines. Cottet-Emard and Goetgheluck
[14] remain pessimistic on this subject: Indeed, the execution time of F (n) is proportional to
20.694 n ≈ (1.6)n, thus one will need 1,6 times more time to calculate than . And under the Moore’s
law, computers become 1,6 times faster each year. Thus, if we can reasonably calculate with this
year technology, then the next year we will calculate. And the following year , and so on: just a
Fibonacci’s number moreover each year! Such is the misfortune of exponential time.
In short, our naive and recursive algorithm is correct but hopelessly ineffective. We will need, to
This graph represents the time complexity Big O of three different approaches used to
determine nth number of Fibonacci series. YELLOW line represents time complexity of explicit
approach. Grey line on the graph shows time complexity of iterative approach. Orange line
The graph shows that initially iterative and recursive approaches behave more like
similarly for the values of n but for the greater values of n recursive approach takes more time
than iterative and explicit approach. As its time complexity is O (2n) exponential.
13
Moreover Iterative function take less time than recursive approach but it is not as
efficient as it has linear time complexity and explicit approach has constant time complexity as
Fig (3.2)
14
4. Abstract
This report deals with algorithmic complexity used in the determination of sum of n natural
numbers. While exposing three correct algorithms, we have, in the light of complexity study of
each one of them, released the one that is optimal.
5. Methods of Computation
There are mainly three methods to compute sum of n natural numbers. Each section of this report
will describe one method (and closely related methods) of computing the sum of n natural
numbers.
return 0;
}
Time complexity
T(n) = T(n-1) + 1
BIG-O
O (n)
15
Fig (5.1)
16
sum += i; _______________________________ n
}
Time complexity
T(n) = 2n
BIG-O
O (n)
Fig (5.2)
18
int main()
{
clock_t tStart = clock();
int n, sum ;
cout << "Enter a positive integer: ";
cin >> n;
return 0;
}
Time complexity
T(n) = n2 + n/2
BIG-O
O (n2)
Fig (5.3)
20
Time Complexity Analysis sum of nth natural number using different methods