0% found this document useful (0 votes)
57 views38 pages

Models of Computation: Analysis of Algorithms Week 1, Lecture 2

This document discusses various models of computation including random access machines (RAM), straight line programs, circuits, vector machines, Turing machines, pointer machines, and decision trees. It covers complexity measures such as time and space complexity, and cost criteria like uniform and logarithmic costs. Reductions between Turing machines and RAM are presented. Extensions including modifiable programs, randomization, non-uniformity, and nondeterminism are also summarized. Key results on derandomization and the relationship between P and NP are highlighted.

Uploaded by

sriniefs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views38 pages

Models of Computation: Analysis of Algorithms Week 1, Lecture 2

This document discusses various models of computation including random access machines (RAM), straight line programs, circuits, vector machines, Turing machines, pointer machines, and decision trees. It covers complexity measures such as time and space complexity, and cost criteria like uniform and logarithmic costs. Reductions between Turing machines and RAM are presented. Extensions including modifiable programs, randomization, non-uniformity, and nondeterminism are also summarized. Key results on derandomization and the relationship between P and NP are highlighted.

Uploaded by

sriniefs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 38

Models of Computation

Analysis of Algorithms
Week 1, Lecture 2

Prepared by

John Reif, Ph.D.


Distinguished Professor of Computer Science
Duke University

Models of Computation (RAM)


a)
b)
c)
d)
e)
f)
g)

Random Access Machines


Straight Line Programs and Circuits
Vector Machines
Turing Machines
Pointer Machines
Decision Trees
Machines That Make Random Choices

Readings
Main Reading Selection:
CLR, Chapter 1 and 2

Random Access Machine


(RAM)

RAM Assumptions
1) Each register holds an integer
2) Program cant modify itself
3) Memory instructions involve simple
arithmetic
a) Addition, subtraction
b) Multiplication, division and control
states (got, if-then, etc.)

Simplified Program Style

Complexity Measures of
Algorithms
Input X
size n=|X|

=> Algorithm A

=>

output

TimeA (X) = time cost of Algorithm A,


input X
SpaceA (X) = space cost of Algorithm
A, input X
Note: time and space depend on
machine

Complexity Measures of
Algorithms (contd)
Worst case
time complexity

TA (n) = max (Time A (X))


{x:|x|=n}

Average case complexity E(TA (n))= Time A (X)Prob(X)


for random inputs
{x:|x|=n}
Worst case
space complexity

SA (n) = max (Space A (X))


{x:|x|=n}

Average case complexity E(SA (n))= Space A (X)Prob(X)


for random inputs
{x:|x|=n}

Cost Criteria
Uniform Cost Criteria
Time = # RAM instructions
space = # RAM memory registers
Logarithmic Cost Criteria
Time= L(i) units per RAM instruction
on integer size i
Space = L(i) units per RAM register
on integer size i

Cost Criteria (contd)


log |i|

where L(i) =

i0
i0

Example

Z 2
for k=1 to n do Z Z Z
ouput Z = 2

2n

Uniform
Logarithmic

time cost = n
time cost > 2n

Varieties of Computing
Machine Models
RAMs
Straight line programs
Circuits
Bit vectors
Lisp machines

Turning Machines

Straight Line Programs


Idea
fix n = input size
unroll each iteration loop until result
is loop-free program Pn

For each n > 0,


get a distinct program Pn

Note: this is only possible if we can


eliminate all branching and all indirect
addressing

Example
Given polynomial

p(x) = a n x n + a n-1x n-1 + ... + a1x + a 0


with constant coefficients a0, a1, , an
Horners Rule for Polynomial Evaluation
RAM
program
in 2n
steps

input X
Y an

for i = n-1 by -1 to 0 do Y (Y X) + a i
ouput Y

Example (contd)

Straight
Line
Programs

Circuits

1-1
correspondence

(DAG) graph model for straight line


programs

Boolean Circuits (for VLSI


Design)

Restrictions
1) All memory registers have value 0 or 1
2) Use only logical operations

and

or

parity

not

Vector Machines
logical operations , ,
vector elements

applied to

memory locations hold Boolean vectors

may also allow vector shift operations

Vector Machines (contd)


Example
graph G

Decision Trees

Decision Trees (contd)


To sort n keys
Any decision tree must have
n! output leaves
(n! = # permutations of n keys)
hence height of tree is

log 2 (n!) c n log n

Pointer Machines
Based on LISP programming
language

The Turing Machine (TM):


The VW of Machines
Invented by Turing (a Cambridge logician)
Built by British for WWII cryptography !

The Turing Machine (contd)


T(n) = time cost

= max steps of TM

S(n) = space cost

= max cells written by


TM on memory tapes

Reductions Between TM and


RAM Models
1) Given TM time cost T(n) then
equivalent RAM (obvious)
Time c T(n)
if uniform cost
Time
cost c T(n) (log n) if log cost
cost
2) Given RAM time cost T(n) with
logarithmic cost then

equivalent TM with time cost c T(n)2

Reductions Between TM and


RAM Models (contd)
registers

Proof idea
Read
write
memory

Do arithmetic by Grammar School


Method

Extensions of RAMS
Reasonable:
(0) Modifiable Program
(1) Random Choices
(2) Non-uniformity
Not Reasonable:
(3) Non-deterministic Choices

RASP Machine
Same as RAM but allow
program to change itself
Same power as RAM
Proof idea (due to Von Neumann)
Let RAM use memory registers to
store modifiable program of RASP

Randomized Machines
Extend RAM instructions to include
r RANDOM(k) gives a random k
bit number
Let AR(x) denote randomized
algorithm with input x, random
choices R

Expected Time input X


Time (X) Prob (R)
Time (X)
R
Expected Time Complexity
T(n) = max Time (x)
{x|n = |x|}

P
R
O
B
A
B
I
L
I
T
Y
TIME
T(n)

A Randomized Computation

1) If machine outputs value v with prob >


then v is considered its output.
2) Machine accepts input X if outputs 1
with prob >
3) Has 1-sided error if when not accepting
1 outputs only 0.

Non-Uniformity
For each input size n, allow the program
a distinct, finite, advice tape to read

Note:
If advice tape length 2n can solve any
Boolean output problem with n
Boolean inputs (obvious).

Surprising Result (Adelman)


Given any polynomial time randomized
algorithm with 1 side error,

a non-uniform deterministic
algorithm with polynomial time and
polynomial advice!
Gives way of derandomizing a
randomized algorithm

Nondeterministic Machines
Allow nondeterministic choice branches

accept x

reject x

If any sequence of choices succeed to accept


x, then computation accepts.

NP and P
NP = languages accepted by
polynomial time nondeterministic TM
machines.
Includes many hard problems:
1) Traveling Salesman Problem
2) Propositional Satisfiability
3) Integer Programming
P = languages accepted by
polynomial time deterministic
machines
?
Not known
P = NP probably no

Another Surprising Result


(Levin)
If P=NP but we dont know the proof
(i.e., the polynomial time algorithm for
NP)
find an optimal algorithm to find the
solution of any solvable search
problem, in polynomial time!
Proof depends on assumption that there
is a finite length program for NP search
problems, running in poly time)

Conclusion
1) There are many possible 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!

Models of Computation
Analysis of Algorithms
Week 1, Lecture 2

Prepared by

John Reif, Ph.D.


Distinguished Professor of Computer Science
Duke University

You might also like