Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
ECE750 Lecture 1: Asymptotics, Resources,
& Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Electrical & Computer Engineering
University of Waterloo
Canada
Sept. 11, 2008
1 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Part I
Asymptotics
2 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Asymptotics: Motivation I
, n
1/2
for
latency-throughput, HINT curves for linear algebra
(characterize performance through dierent cache
regimes), etc.
...
3 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Asymptotics: Motivation II
f _ g (f is asymptotically dominated by g)
Transitive: (x y) (y z) (x z)
Reexive: x x
Symmetric: (x y) (y x).
Basic idea: We only care about the leading term,
disregarding less quickly-growing terms.
7 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Basic asymptotic notations III
f _ g means limsup
n
f (n)
g(n)
<
i.e.,
f (n)
g(n)
is eventually bounded by a nite value.
(limsup means the maximum value a function attains
innitely often. For example, lim
x
cosx does not exist,
but limsup
x
cosx = 1.)
Transitive: (f _ g) (g _ h) (f _ h).
Reexive: f _ f
8 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Basic asymptotic notations IV
Variant: g _ f means f _ g.
9 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Basic asymptotic notations V
Write f g when there are positive constants c
1
, c
2
such that
c
1
f (n)
g(n)
c
2
for suciently large n.
Examples:
n 2n
n (2 + sin n)n
is an equivalence relation.
10 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Strict forms
Write f g when f _ g but f , g.
Examples
x
2
x
3
log x x
Variant: f ~ g means g f
11 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Orders of growth I
We can use as a ruler by which to judge the growth of
functions. Some common tick marks on this ruler are:
log log n log n log
k
n n
n n
2
2
n
n! n
n
2
2
n
We can always nd in a dense total order without
endpoints. i.e.,
O(n
2
) contains n
2
, 7n
2
, n, log n, n
3/2
, 5, . . .
Example:
n
k=0
2
k
= 2
1
2
n
= 2 + o(1)
n! = o(n
n
).
19 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Notation: ()
f (g) means f ~ g
h
n
=
n
k=0
1
k
ln n + + O(n
1
)
h
n
(1) (It is unbounded.)
h
n
(ln ln n)
n! = (2
n
) (grows faster than 2
n
)
20 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Notation: ()
f (g) means f _ g
_
n + O(n
1/2
)
_
= n ln n + n + O(n
1/2
ln n)
The terms O(n
1/2
), O(n
1/2
), O(1), etc. get
swallowed by O(n
1/2
ln n).
23 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Sharpness of estimates
Example: for a constant c,
ln(n + c) = ln
_
n
_
1 +
c
n
__
= ln n + ln
_
1 +
c
n
_
= ln n +
c
n
c
2
2n
2
+ (Maclaurin series)
= ln n +
_
1
n
_
It is also correct to write
ln(n + c) = ln n + O(n
1
)
ln(n + c) = ln n + o(1)
since (n
1
) O(
1
n
) o(1). However, the (
1
n
) error term
is sharper a better estimate of the error.
24 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Sharpness of estimates & The Riemann
Hypothesis
Example: let (n) be the number of prime numbers n.
The Prime Number Theorem is that
(n) Li(n) (1)
where Li(n) =
_
n
x=2
1
ln x
dx is the logarithmic integral, and
Li(n)
n
ln n
Note that (1) is equivalent to:
(n) = Li(n) + o(Li(n))
It is known that the error term can be improved, for example
to
(n) = Li(n) + O
_
n
ln n
e
a
ln n
_
25 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Sharpness of estimates & The Riemann
Hypothesis
The famous Riemann hypothesis is the conjecture that a
sharper error estimate is true:
(n) = Li(n) + O(n
1
2
ln n)
This is one of the Clay Institute millenium problems, with a
$1,000,000 reward for a positive proof. Sharp estimates
matter!
26 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Sharpness of estimates
To maintain sharpness of asymptotic estimates during
analysis, some caution is required.
E.g. If f (n) = 2
n
+ O(n), what is log f (n)?
Bad answer: log f (n) = n + o(n).
More careful answer:
log f (n) = log(2
n
+ O(n))
= log(2
n
(1 + O(n2
n
)))
= log(2
n
) + log(1 + O(n2
n
))
Since log(1 + (n)) O((n)) if o(1),
log f (n) = n + O(n2
n
)
i.e., log f (n) is equal to n plus some value converging
exponentially fast to 0.
27 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Sharpness of estimates
log f (n) = n + O(n2
n
)
is a reasonably sharp estimate (but, what happens if we take
2
log f (n)
with this estimate?)
If we dont care about the rate of convergence we can write
f (n) = n + o(1)
where o(1) represents some function converging to zero.
This is less sharp since we have lost the rate of convergence.
Even less sharp is
f (n) n
which loses the idea that f (n) n 0, and doesnt rule out
things like f (n) = n + n
3/4
.
28 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Asymptotic expansions I
An asymptotic expansion of a function describes how that
function behaves for large values. Often it is used when an
explicit description of the function is too messy or hard to
derive.
e.g. if I choose a string of n bits uniformly at random (i.e.,
each of the 2
n
possible strings has probability 2
n
), what is
the probability of getting
3
4
n 1s?
Easy to write the answer: there are
_
n
k
_
ways of arranging k
1s, so the probability of getting
3
4
n 1s is:
P(n) =
n
k=
3
4
n
2
n
_
n
k
_
This equation is both exact and wholly uninformative.
Can we do better? Yes!
29 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Asymptotic expansions II
The number of 1s in a random bit string is a binomial
distribution and is well-approximated by the normal
distribution as n :
n
k=
1
2
n+
n
2
n
_
n
k
_
_
x=
1
2
e
x
2
2
dx
= 1 F()
where F(x) =
1
2
_
1 +erf
_
x
2
__
is the cumulative normal
distribution.
Maples asympt command yields the asymptotic expansion:
F(x) 1 O
_
1
xe
x
2
2
_
30 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Asymptotic expansions III
We want to estimate the probability of
3
4
n 1s:
1
2
n +
n =
3
4
n
gives =
n
4
. Therefore the probability is
P(n) 1 F
_
n
4
_
1 1 + O
_
1
ne
n
32
_
= O
_
1
ne
n
32
_
So, the probability of having more than
3
4
n 1s converges to
0 exponentially fast.
31 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Asymptotic Expansions
function
[continuous derivatives of all orders exist] about x = 0
is given by:
f (x) = f (0) + xf
(0) +
x
2
2!
f
(0) +
x
3
3!
f
(0) +
Advanced:
Number of gates
Depth
Area
Heat production
Number of processors
Error probability
41 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Machine models I
O(d) space
fan-out
area
n
Carry lookahead 14n 4 log n
Conditional-sum adder 3n log n 2 log n
46 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Resource consumption tradeos I
Choosing k =
1
2
log n yields time (log
4
n) and
probability of error
1
n
.
Cracking passwords has a time-space tradeo:
a style of problem
Complexity classes:
There are 2
0
(uncountably many) problems
subsets of A N. (They can be put into 1-1
correspondence with the reals.)
me professors
me programmers
professors people
programmers people
53 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
An aside: Hasse diagrams II
people
professors
o
o
o
o
o
o
o
programmers
Q
Q
Q
Q
Q
Q
Q
Q
me
N
N
N
N
N
N
N
n
n
n
n
n
n
n
n
n
54 / 64
ECE750 Lecture 1:
Asymptotics,
Resources, &
Complexity Classes
Todd Veldhuizen
tveldhui@acm.org
Whirlwind tour of major complexity classes I