Professional Documents
Culture Documents
REPORT
Laboratory work nr.1
Complexity and Calculability
Chisinau 2020
Tema: Algorithm Analysis
This famous string was discovered in 1202 by Leonardo Pisano (Leonardo of Pisa), known as
Leonardo Fibonacci. The nth term of the string can be obtained directly from the definition:
function fib1(n)
if n < 2 then return n
else return fib1(n-1) + fib1(n-2)
This method is very inefficient, because it recalculates the same values several times. Here's
another, more efficient method that solves the same problem.
function fib2(n)
i ← 1; j ← 0
for k ← 1 to n do j ← i + j
i ← j - i
return j
Another algorithm:
function fib3(n)
i ← 1; j ← 0; k ← 0; h ← 1
while n > 0 do
if n este impar then t ← jh
j ← ih+jk+t
i ← ik+t
t ←h
2
h ← 2kh+t
k ← k2+t
n ← n div 2
return j
Basic task:
Perform the empirical analysis of the proposed algorithms.
Determine the relationship that determines the temporal complexity for these algorithms.
Determine the asymptotic complexity of the algorithms.
Make a conclusion about the work done.
Algorithm Description
Algorithm is the fundamental notion of computer science. Everything is built around algorithms
(and data structures, such as lists or graphs). It is also a fundamental concept of modern
mathematics alongside that of axiomatic system
Often, in order to solve a problem, an algorithm has to be chosen from several possible ones, two
main criteria of choice being contradictory: the algorithm is simple to understand, to code and to
debug; the algorithm to use the computer resources efficiently, to have a short execution time. If
the program to be written needs to be run a small number of times, the first requirement is more
important; In this situation, the time to set up the program is more important than its running
time, so the simplest version of the program must be chosen. If the program is to be run a large
number of times, with a large number of data to be processed, the algorithm that results in faster
execution must be chosen. Even in this situation, the simpler algorithm should be implemented
earlier and the runtime reduction that the complex algorithm implementation would bring should
be calculated.
- to compare the efficiency of two (or more) algorithms for solving the same problem;
}
Screen
Results
Nr.
n=10 n=20 n=30 n=40
Alg.
Iterations:54 Iteration:6764 Iteration: 832039 Iteration: 102334154
1
Time:0.003 Time:0.003 Time: 0.078 Time: 9.29
Probably most of us have never taken the time to examine very carefully the number or
arrangement of petals on a flower. If we were to do so, we would find that the number of petals
on a flower that still has all of its petals intact and has not lost any, for many flowers is a
Fibonacci number (Internet access,8).
• 1 petal: white cally lily
Fibonacci in Music
The Fibonacci sequence of numbers and the golden ratio are manifested in music widely.
The numbers are present in the octave, the foundational unit of melody and harmony.
Stradivarius used the golden ratio to make the greatest string instruments ever created.
Howat’s( 1983) research on Debussy’s works shows that the composer used the golden ratio and
Fibonacci numbers to structure his music. The Fibonacci Composition reveals the inherent
aesthetic appeal of this mathematical phenomenon. Fibonacci numbers harmonize naturally and
the exponential growth which the Fibonacci sequence typically defines in nature is made present
in music by using Fibonacci notes. The intervals between keys on a piano of the same scales are
Fibonacci numbers (Gend, 2014).
Conclusion
As a result of this laboratory work we analyzed 3 different methods of calculating the Fibonaci
string. After running the program we came to the conclusion that different algorithms have
different execution time. All methods work but they differ by efficiency. The execution time is
very small and the number of iterations for large numbers does not increase very quickly.