meljun cortes automata theory 21
TRANSCRIPT
-
8/13/2019 MELJUN CORTES Automata Theory 21
1/36
CSC 3130: Automata theory and formal languages
Polynomial time
Fall 2008MELJUN P. CORTES MBA MPA BSCS ACS
MELJUN CORTES
-
8/13/2019 MELJUN CORTES Automata Theory 21
2/36
Efficient algorithms
The running time of analgorithm depends onthe input
For longer inputs, weallow more time
Efficiency is measuredas a function of inputsize
A TMPCP
-
8/13/2019 MELJUN CORTES Automata Theory 21
3/36
Examples of running time
parsingproblem
running time
0n 1n
algorithm LR(1)
O( n ) O( n ) O( n log n )
short paths
Dijkstra
matching
Edmonds
O( n 3 )
CYK
O( n 2 )
n = input size
running time
problem routing
2O( n )
scheduling
2O( n log n ) 2O( n )
theorem proving
-
8/13/2019 MELJUN CORTES Automata Theory 21
4/36
Input representation
Since we measure efficiency in terms of inputsize , how the input is represented will make adifference
For us, any reasonable representation will beokayThe number 17
17
10001 (17 in base two)11111111111111111
OKOKNO
This graph
0000,0010,0001,00101 2
3 4OK
(2,3),(3,4) OK
-
8/13/2019 MELJUN CORTES Automata Theory 21
5/36
Measuring running time
What does it mean when we say:
One step in
all mean different things!
This algorithm runs in 1000 steps
java RAM machine Turing Machineif (x > 0)
y = 5*y + x;write r3; d (q 3, a) = (q 7, b, R)
-
8/13/2019 MELJUN CORTES Automata Theory 21
6/36
Example
L = {0 n 1n : n > 0}
in java:
M(string x) {n = x.len;if n % 2 == 0 reject;else
for (i = 0; i
-
8/13/2019 MELJUN CORTES Automata Theory 21
7/36
Efficiency and the Church-Turing thesis
The Church-Turing thesis says all these modelsare equivalent in power
but not in running time!
java
RAM machine
Turing Machine
multitape TM
UNIVAC
-
8/13/2019 MELJUN CORTES Automata Theory 21
8/36
The Cobham-Edmonds thesis
However, there is an extension to the Church-Turing thesis that says
For any realistic models of computation M 1 and
M 2:
So any task that takes time T on M 1 can be donein time (say) T 2 or T 3 on M 2
M 1 can be simulated on M 2 with at mostpolynomial slowdown
-
8/13/2019 MELJUN CORTES Automata Theory 21
9/36
Efficient simulation
The running time of a program depends on themodel of computation
but in the grand scheme, this is irrelevant
javaRAM machinemultitape TMordinary TMfastslow
Every reasonable model of computation can besimulated efficiently on every other
-
8/13/2019 MELJUN CORTES Automata Theory 21
10/36
Example of efficient simulation
Recall simulating multiple tapes on a single tape
M 0 1 0
0 1
1 0 0
G = {0, 1, }
S 0 1 0 10 # # 0 #1 0
G = {0, 1, , 0, 1, , #}
#
-
8/13/2019 MELJUN CORTES Automata Theory 21
11/36
Running time of simulation
Each move of the multiple tape TM might requiretraversing the whole single tape
after t steps
O( s ) steps of single tape TM
s = rightmost cell ever visited
s 3 t + 4
1 step of 3-tape TM
t steps of 3-tape O( ts ) = O ( t 2 ) single tape steps
multi-tape TM single tape TMquadraticslowdown
-
8/13/2019 MELJUN CORTES Automata Theory 21
12/36
Simulation slowdown
Cobham-Edmonds Thesis:
multi-tapeTM java
single tape TMRAM machine
O( t ) O( t )
O( t 2 )
O( t 2 )
O( t )O( t )
M 1 can be simulated on M 2 with at mostpolynomial slowdown
-
8/13/2019 MELJUN CORTES Automata Theory 21
13/36
Running time of nondeterministic TM
What about nondeterministic TMs?
For ordinary TMs, the running time of M on inputx is the number of transitions M makes before ithalts
But a nondeterministic TM can run for a differenttime on different computation paths
-
8/13/2019 MELJUN CORTES Automata Theory 21
14/36
Example
Definition of running time for nondeterministic TM
q acc
q 0 1/1R
0/0Rq 1
10001
what is the running time?
q rej
running time =
computation path: any possible sequence of transitions
max length of any computation path
5
-
8/13/2019 MELJUN CORTES Automata Theory 21
15/36
Simulation of nondeterministic TM
nondet TMmulti-tape
TM
1 00
1 00
2 21
input tape x
1
simulation tape z
address tape aFor all k > 0For all possible strings a of length kCopy x to z.Simulate N on input z using a as choices
If a specifies an invalid choice orsimulation loops/rejects, abandon simulation.
If N enters its accept state, accept and halt.If N rejected on all a s of length k, reject and halt.
representspossible choicesat each step
each a describesa possiblecomputation
path
N M
-
8/13/2019 MELJUN CORTES Automata Theory 21
16/36
Simulation slowdown fornondeterminism
For all k > 0For all possible strings a of length kCopy x to z.Simulate N on input z using a as choices
If a specifies an invalid choice or
simulation loops/rejects, abandonsimulation.If N enters its accept state, accept and
halt.If N rejected on all a s of length k, reject and
halt.simulation will halt when k = trunning time of N is t
running time of simulation = ( running time for specific a ) ( number of a s of length t )
= O( t ) 2O( t ) = 2 O( t )
-
8/13/2019 MELJUN CORTES Automata Theory 21
17/36
Simulation slowdown
multi-tapeTM java
single tape TMRAM machine
O( t ) O( t )O( t 2 )
O( t 2 )O( t )
O( t )
nondeterministic TM
2O( t )
Do nondeterministic TM violate the Cobham-Edmonds thesis
-
8/13/2019 MELJUN CORTES Automata Theory 21
18/36
Nondeterminism and the CE thesis
Cobham-Edmonds Thesis says:
But is nondetermistic computation realistic?
Any two realistic models of computationcan be simulated with polynomial slowdown
-
8/13/2019 MELJUN CORTES Automata Theory 21
19/36
Example
Recall the scheduling problem
Scheduling with nondeterminism:
CSC 3230 CSC 2110
CSC 3160CSC 3130
Can you schedule final examsso that there are no conflicts ?
Exams vertices
Slots colors
Conflicts edges
Y R B
schedule(int n, Edges edges) { for i := 1 to n:
choose { c[i] := Y; }or { c[i] := R; }
or { c[i] := B; }for all e in edges:
if c[e.left] == c[e.right]reject;
accept;}
-
8/13/2019 MELJUN CORTES Automata Theory 21
20/36
-
8/13/2019 MELJUN CORTES Automata Theory 21
21/36
Nondeterministic simulation
If we can do better, this would improve all known combinatorial optimization algorithms!
nondeterministic TM multi-tapeTM
2O( t ) slowdown
Is this the best we can do?
-
8/13/2019 MELJUN CORTES Automata Theory 21
22/36
Millenium prize problems
Recall how in 1900, Hilbert gave 23 problemsthat guided mathematics in the 20 th century
In 2000, the Clay Mathematical Institute gave 7problems for the 21 st century
1 P versus NP2 The Hodge conjecture3 The Poincar conjecture4 The Riemann hypothesis5 Yang Mills existence and mass gap6 Navier Stokes existence andsmoothness7 The Birch and Swinnerton-Dyer
conjecture
$1,000,000
Hilberts 8 th problemPerelman 2006 (refused money)
computer science
-
8/13/2019 MELJUN CORTES Automata Theory 21
23/36
The P versus NP question
Among other things, this asks: Is nondeterminism a realistic feature of computation? Can the choose construct be efficiently implemented? Can we efficiently optimize any well -posed problem?
nondeterministic TM ordinary TM
Can nondeterministic TM be simulated onordinary TM with polynomial slowdown?
poly( t )
Most people think not,but nobody knows for sure!
-
8/13/2019 MELJUN CORTES Automata Theory 21
24/36
The class P
P is the class of all languagesthat can be decided on anordinary TM whose running
time is some polynomialin the length of the input
By the CE thesis, we can replaceordinary TM by any realistic model of computation
multi-tape TM java RAM
-
8/13/2019 MELJUN CORTES Automata Theory 21
25/36
Examples of languages in P
parsingproblem
running time
0n 1n
algorithm LR(1)
O( n ) O( n ) O( n log n )
short paths
Dijkstra
matching
Edmonds
O( n 3 )
CYK
O( n 2 )
n = input size
L 01 = {0 n 1n : n > 0}
L G = { x : x is generated by G}
PATH = {(G, a , b , L ): G is a graph with apath of length L from a to b }
G is some CFG
MATCH = {G, a , b , L : G is a graph with aperfect matching } context-free
P (efficient)
decidable
L 01
L GPATH MATCH
-
8/13/2019 MELJUN CORTES Automata Theory 21
26/36
Languages believed to be outside P
running timeof best-known algorithm
problem routing2O( n )
scheduling
2O( n ) 2O( n )thm-proving
We do not know if theseproblems have faster algorithms,but we suspect not
P (efficient)
decidable
L GPATH
MATCH
ROUTESCHED
PROVE?
To explain why, first we needto understand what theseproblems have in common
-
8/13/2019 MELJUN CORTES Automata Theory 21
27/36
More problems
1 2
3 4
Graph G
A clique is a subset of verticesthat are all interconnected
{1, 4}, {2, 3, 4}, {1} are cliques
An independent set is a subset ofvertices so that no pair is connected
{1, 2}, {1, 3}, {4} are independent setsthere is no independent set of size 3
A vertex cover is a set of verticesthat touches (covers) all edges
{2, 4}, {3, 4}, {1, 2, 3} are vertex covers
-
8/13/2019 MELJUN CORTES Automata Theory 21
28/36
Boolean formula satisfiability
A boolean formula is an expression made up ofvariables, ands, ors, and negations, like
The formula is satisfiable if one can assignvalues to the variables so the expressionevaluates to true
( x 1 x 2 ) ( x 2 x 3 x 4 ) ( x 1 )
x 1 = F x 2 = F x 3 = T x 4 = T Above formula is satisfiable because this assignmentmakes it true:
-
8/13/2019 MELJUN CORTES Automata Theory 21
29/36
Status of these problems
CLIQUE = {(G, k ): G is a graph with a clique of k vertices }
IS = {(G, k ): G is a graph with an independent set of k vertices }
VC = {(G, k ): G is a graph with a vertex cover of k vertices }
SAT = { f : f is a satisfiable Boolean formula }
running time
of best-known algorithm
problem CLIQUE
2O( n )
IS
2O( n )
SAT
2O( n )
VC
2O( n )
What do these problems have in common ?
-
8/13/2019 MELJUN CORTES Automata Theory 21
30/36
Checking solutions efficiently
We dont know how to solve them efficiently
But if someone told us the solution, we would beable to check it very quickly
1
2
3
4
5
6
78
9
10
11
12
13
14
15
Is (G, 5) in CLIQUE ?
1,5,9,12,14
Example:
-
8/13/2019 MELJUN CORTES Automata Theory 21
31/36
Cliques via nondeterminism
Checking solutions efficiently is equivalent todesigning efficient nondeterministic algorithms
Is (G, k ) in CLIQUE ?Example:clique(Graph G, int k) { C = {}; % potential clique
for i := 1 to G.n: % choose cliquechoose { C := union(C, {i}); }
or {}if size(C) != k reject; % check size is kfor i := 1 to G.n: % check all edges
for j := 1 to G.n: % are inif i in C and j in C
if G.isedge(i,j) == falsereject;
accept;}
-
8/13/2019 MELJUN CORTES Automata Theory 21
32/36
Example: Formula satisfiability
( x 1 x 2 ) ( x 2 x 3 x 4 ) ( x 1 ) f =
Checking solution: Nondeterministic algorithm:
FFTTsubstitutex 1 = F x 2 = F x 3 = T x 4 = T
evaluate formula
( F T ) ( F T F ) ( T ) f =can be done in linear time
sat(Formula f) { x = new bool[f.n];for i := 1 to n:
choose { x[i] := true; }or { x[i] := false; }
if f.eval(x) == true accept;else reject;
}
-
8/13/2019 MELJUN CORTES Automata Theory 21
33/36
The class NP
The class NP :
L can be solved on a nondeterministic TM inpolynomial time iff its solutions can bechecked intime polynomial in the input length
NP is the class of all languages that can bedecided on a nondeterministic TM whoserunning time is some polynomial in the lengthof the input
-
8/13/2019 MELJUN CORTES Automata Theory 21
34/36
P versus NP
because an ordinaryTM is only weaker
than anondeterministic one
Conceptually, finding solutions can only beharder than checking them
P (efficient)
decidable
L GPATH
MATCH
CLIQUE
SAT ISNP (efficiently checkable)
VC
P is contained inNP
-
8/13/2019 MELJUN CORTES Automata Theory 21
35/36
P versus NP
The answer to the question
is not known. But one reason it is believed to benegative is because, intuitively, searching isharder than verifying
For example, solving homework problems(searching for solutions) is harder than grading (verifying the solution is correct)
Is P equal toNP?
$1,000,000
-
8/13/2019 MELJUN CORTES Automata Theory 21
36/36
Searching versus verifying
Mathematician:Given a mathematical claim, come up with a proof for it.
Scientist:Given a collection of data on some phenomena, nd a
theory explaining it.
Engineer:Given a set of constraints (on cost, physical laws, etc.)
come up with a design (of an engine, bridge, etc) whichmeets them.
Detective:Given the crime scene, nd whos done it.