Time Complexity
-
Upload
francesca-roberts -
Category
Documents
-
view
34 -
download
1
description
Transcript of Time Complexity
Fall 2006 Costas Busch - RPI 3
For any string the computation ofterminates in a finite amount of transitions
w M
Acceptor Reject w
Initialstate
Fall 2006 Costas Busch - RPI 5
Consider now all strings of lengthn
)(nTM = maximum time required to decide any string of length n
Fall 2006 Costas Busch - RPI 6
)(nTM
Max time to accept a string of length n
1 2 3 4 n STRING LENGTH
TIM
E
Fall 2006 Costas Busch - RPI 7
Time Complexity Class: ))(( nTTIME
All Languages decidable by a deterministic Turing Machinein time
1L 2L
3L
))(( nTO
Fall 2006 Costas Busch - RPI 8
Example: }0:{1 nbaL n
This can be decided in time)(nO
)(nTIME
}0:{1 nbaL n
Fall 2006 Costas Busch - RPI 9
)(nTIME
}0:{1 nbaL n
}0,:{ knabaabn
}even is :{ nbn
Other example problems in the same class
}3:{ knbn
Fall 2006 Costas Busch - RPI 11
)( 3nTIMEExamples in class:
} grammar free-context
by generated is :,{2
G
wwGL
} and
matrices :,,{
321
3213
MMM
nnMMML
CYK algorithm
Matrix multiplication
Fall 2006 Costas Busch - RPI 12
Polynomial time algorithms: )( knTIME
Represents tractable algorithms:
for small we can decidethe result fast
k
constant 0k
Fall 2006 Costas Busch - RPI 14
0
)(
k
knTIMEP
The Time Complexity Class P
•“tractable” problems
•polynomial time algorithms
Represents:
Fall 2006 Costas Busch - RPI 16
Exponential time algorithms: )2(knTIME
Represent intractable algorithms:
Some problem instancesmay take centuries to solve
Fall 2006 Costas Busch - RPI 17
Example: the Hamiltonian Path Problem
Question: is there a Hamiltonian path from s to t?
s t
Fall 2006 Costas Busch - RPI 19
)2()!(knTIMEnTIMEL
Exponential time
Intractable problem
A solution: search exhaustively all paths
L = {<G,s,t>: there is a Hamiltonian path in G from s to t}
Fall 2006 Costas Busch - RPI 22
Example: The Satisfiability Problem
Boolean expressions inConjunctive Normal Form:
ktttt 321
pi xxxxt 321
Variables
Question: is the expression satisfiable?
clauses
Fall 2006 Costas Busch - RPI 25
e}satisfiabl is expression :{ wwL
)2(knTIMEL
Algorithm: search exhaustively all the possible binary values of the variables
exponential
Fall 2006 Costas Busch - RPI 26
Non-Determinism
Language class: ))(( nTNTIME
A Non-Deterministic Turing Machine decides each string of length in time
1L
2L3L
))(( nTO
n
Fall 2006 Costas Busch - RPI 29
Example: The satisfiability problem
Non-Deterministic algorithm:
•Guess an assignment of the variables
e}satisfiabl is expression :{ wwL
•Check if this is a satisfying assignment
Fall 2006 Costas Busch - RPI 30
Time for variables: n
)(nO
e}satisfiabl is expression :{ wwL
Total time:
•Guess an assignment of the variables
•Check if this is a satisfying assignment )(nO
)(nO
Fall 2006 Costas Busch - RPI 31
e}satisfiabl is expression :{ wwL
NPL
The satisfiability problem is an - ProblemNP
Fall 2006 Costas Busch - RPI 32
Observation:
NPP
DeterministicPolynomial
Non-DeterministicPolynomial