Professional Documents
Culture Documents
Algorithms
Professor John Reif
ALG 1.1
Read-only
input tape
Xn
r0
location
counter
Models of Computation:
...
Program
Accumulator
r1
r2
..
.
Y1
Memory
Registers
...
write-only output tape
RAM assumptions
(1)
(2)
(3)
input X
size n = |X|
fi
Algorithm A
fi
output
a) addition, subtraction
b) multiplication, division
Space
worst case
time complexity
r3 r1 op r2
op {+, -, , }
examples:
goto label
if r = 0 then goto L
read ( r )
write ( r )
average case
complexity
for random inputs
worst case
space complexity
average case
complexity
for random inputs
"
E(T A (n)) =
"
(X))
S Time A(X)Prob(X)
{x:|x|=n}
SA (n) =max(Space
(x))
{x:|x|=n}
E(S A (n)) =
S Space A (x)Prob(x)
{x:|x|=n}
{
{
t i me =# RA M i n s t r u c t i on s
Varieties of
Computing Machine
Models
s p ac e =# RA M me mor y r e gi s t e r s
wh e r e L( i ) =
example
Z2
for k = 1
uniform
logarithmic
l og |i | i 0
1
i =0
to n do
output Z = 2
RAMs
straight line programs
circuits
bit vectors
lisp machines
..
.
Turing Machines
2 n
Z Z Z
time cost = n
time cost > 2 n
5
Example
Given polynomial
n
p ( x ) = an x + an - 1 x
n- 1
+ . . . + a1 x + a0
Horner's Rule
for
Polynomial
Evaluation
RA M
p r ogr am
i n 2 n s t e ps
,a 1 ,...,a
n=1
P1 :
Y a1 X
Y Y + a0
i np ut X
Y an
f or i = n - 1 b y - 1 t o 0 d o
Y ( Y X) + a i
ou t p u t Y
n=2
Y a2 X
Y Y + a1
Y Y X
Y Y + a0
n=3
Y
Y
Y
Y
Y
Y
a3 X
Y + a2
Y X
Y + a1
Y X
Y + a
fi fi
Straight Line
Programs
1-1
correspondence
input
Y a3
Y Y
+ a
2
Y Y
Y Y
a1
Y Y
Y Y
a0
inputs
a2
a3
Boolean Circuits
Circuits
a1
x1
x2
a0
output
restrictions:
output
value 0 or 1
, , ,
10
Decision Trees
Vector Machines
Example
vector
Sorting
, , ,
logical operations
a<b?
N
elements
Y
b<c?
boolean vectors
Y
...
input a,b,c
0
output
a,b,c
1
1
2
1
3
0
graph G
0
1
output
a,c,b
output
b,a,c
b<c?
output
c,a,b
output
b,c,a
output
c,b,a
To sort n keys
any decision tree must have
n! output leaves
1
0
a<c?
Y
Example
a<c?
>log (n!)
2
11
>c n log n
12
Lisp Machines
"The VW of Machines"
...
xn
input tape
registers
r
r
program
...
Y 1 Y2
...
X1 X2
input tape
0
Finite State
Control
1
2
Yn
Y2
read/write
memory tapes
write only
output tape
output tape
Invented by Turing
operations
CDR (r)
...
Heap
read only
...
x1 x
r i CAR ( r )
CAR
CDR
r i CDR ( r j )
CAR ( r i )
CELL
CDR (r i)
(a Cambridge logician)
13
T(n) =
time cost
= max steps of TM
S(n) =
space cost
14
Reductions
between
TM and RAM
models
(1) Given
$ equivalent
time
cost
then
Ram (obvious)
Extensions of RAMS:
Reasonable
c T(n)
if uniform cost
c T(n) (log n)
if logarithmic cost
r1
Not Reasonable
(3) Non-deterministic Choices
idea
proof
registers
r0
(2) Non-uniformity
r2
rk
read
write
memory
15
16
Randomized Machines
Extend RAM
instructions to
include
RASP Machine
same as RAM but allow
r RANDOM(k)
gives a random k
bit number
Expected Time
Proof idea
Time (X)
Let RAM
input X
"R
Time (X)
Prob (R)
Neumann)
17
18
A Randomized Computation
P
T(n)
R
1/2
1/2
O
B
N
1/2
Y
1/2
B
1/2
1/2
1/2
1/2
1/2
1/2
...
...
...
...
...
...
T
Y
output
0
T I M E T(n)
19
output
1
output
0
20
Non-uniformity
(1) If machine
outputs value v with prob >
then v is considered its output.
(2) machine
(3) has
accepts input X
1-sided error
1
2
1
2
21
22
Surprising Result
Nondeterministic
Machines
[Adelman]
nondeterministic
choice
a non-uniform
deterministic
algorithm with polynomial time
and polynomial advice!
( tricky proof )
Gives way of derandomizing
a randomized algorithm.
accept x
reject x
if any
sequence of choices succeed
to accept x, then computation a c c e p t s .
23
24
NP = languages accepted by
polynomial
time nondeterministic
TM machines.
- includes many
hard problems:
If P=NP but we don't know the proof
(i.e., the polynomial time algorithm
for NP
find an optimal algorithm to
find the solution of any
solvable NP search problem,
in polynomial time!
= languages accepted by
polynomial time deterministic
TM machines
not known
probably
no
P = NP
?
25
26
Conclusion
many possible
(1) There are
machine models
(2) Most (but
not Nondeterministic)
are "Constructable" - so might
be used if we have efficient
algorithms to execute on
machines.
(3) New machine models can help
us invent new algorithms , and
vice versa!
27