Module 5 Complexity 2
Module 5 Complexity 2
Module #5:
Algorithmic Complexity
113/10/17 1
Module #7 - Complexity
What is complexity?
The word complexity has a variety of
technical meanings in different fields.
There is a field of complex systems, which
113/10/17 2
Module #7 - Complexity
113/10/17 3
Module #7 - Complexity
113/10/17 4
Module #7 - Complexity
.
Which algorithm will be fastest on all
113/10/17 6
Module #7 - Complexity
113/10/17 8
Module #7 - Complexity
n
t (n) t1 (t 2 t3 ) t 4
i 2
n
(1) (1) (1) (1) (n 1)(1)
i 2
(1) (n)(1) (1) (n) (n)
113/10/17 9
Module #7 - Complexity
113/10/17 11
Module #7 - Complexity
113/10/17 13
Module #7 - Complexity
113/10/17 14
Module #7 - Complexity
Names for some orders of
growth
(1) Constant
(log n) Logarithmic (same order c)
c
(logc n) Polylogarithmic (With c
(n) Linear a constant.)
(nc) Polynomial
(cn), c>1 Exponential
(n!) Factorial
113/10/17 15
Module #7 - Complexity
Problem Complexity
The complexity of a computational
problem or task is (the order of growth
of) the complexity of the algorithm with
the lowest order of growth of complexity
for solving that problem or performing
that task.
E.g. the problem of searching an
113/10/17 16
Module #7 - Complexity
Tractable Problems
(Deterministic Polynomial algorithm
=> P)
Unsolvable
Problems Untractable Problems
(Non-deterministic Polynomial =>
NP )
113/10/17 17
Module #7 - Complexity
Unsolvable problems
Turing discovered in the 1930’s that
there are problems unsolvable by any
algorithm.
– Or equivalently, there are undecidable
yes/no questions, and uncomputable
functions.
Example: the halting problem.
– Given an arbitrary algorithm and its input,
will that algorithm eventually halt, or will it
continue forever in an “infinite loop?”
113/10/17 18
Module #7 - Complexity
The Proof
Given any arbitrary program H(P,I),
Consider algorithm Breaker, defined as:
113/10/17 20
Module #7 - Complexity
113/10/17 21
Module #7 - Complexity
P vs. NP
NP is the set of problems for which
there exists a tractable algorithm for
checking solutions to see if they are
correct.
We know PNP, but the most famous
113/10/17 22
Module #7 - Complexity
Things to Know
Definitions of algorithmic complexity,
time complexity, worst-case
complexity; names of orders of
growth of complexity.
How to analyze the worst case, best
113/10/17 24
Module #7 - Complexity
For the following procedure A, analyze and provide the worst case time
complexities. We will use the following assumptions:
Suppose A and B are both procedures. B take θ(n) time to compute.
Function A is a recursive one defined as follows
(You can assume m is 2k)
113/10/17 25