Unit 1: Algorithmic Complexity
Unit 1: Algorithmic Complexity
Unit 1: Algorithmic Complexity
ALGORITHMIC COMPLEXITY
1.1: Definition. Time Cost/Complexity
matrices
The biggest value to be computed
It is a mathematical function.
A size of the problem dependant function
which measures the time complexity of the
algorithm.
We are concerned with the behaviour in the
limit, i.e. when such size of the problem
grows.
This is called Asymptotic efficiency
Complexity Function II
Edmonds law:
Tractable problem : Polynomial Complexity
Non-tractable problem: Exponential Complexity
Algorithms which Complexity are
greater than (n·log n) are almost
useless => Better find a “cheaper” one.
Exponentials are only useful as a matter
of theoretical examples.
1.2: Asymptotic Complexity Orders
Behaviours: O, ,
These asymptotic orders, summarize the
behaviour of a given algorithm.
They range over the time taken by the
algorithm when the size of the problem grows
unbounded.
This is the key fact to be taken into account
when we want to compare the efficiency of
two algorithms solving the same problem.
They are valid even for midsized instances
Asymptotic Orders
Big O notation
Given a function f, we want to refer those
functions that at most grows as f does. The
set of these functions is the upper bound of f,
and it is written as O(f).
Once this value is known, we can guarantee
that always the algorithm can be run within
the time upper bounded by this value.
Formally:
g(n)O(f(n)) if c>0, n0 / g(n) c·f(n),nn0
Graphically
Big O notation
cf(n)
g(n)
n0
Example
Big O notation
If the map of g is upper bounded by f then g’s
efficiency is better or equal than that of f.
Constants must be discarded regarding behaviour
issues.
O(f(n)): Set of all the functions which are upper
bounded by f (g belongs to this set).
Example:
P(n) = am·nm + ... + a1·n + a0 (polynomial on “n”)
P(n) O(nm)
Asymptotic Orders
Properties of Big O notation
1. g(n) Є O(g(n))
2. O(c·g(n)) = O(g(n)) (c is constant)
Ex : O(2·n2) = O(n2)
3. O(g(n)+h(n))= max{O(g(n)),O(h(n))}
Ex: O(n+n2) = O(n2)
4. O(g(n)-h(n))=max{O(g(n)),O(h(n))}
Ex: O(n-n2) = O(n2)
Big O notation