Lecture 10
Lecture 10
Adnane Saoud
1
Summary of lecture 7
Lecture 9
• The Reducibility Method to prove undecidability and T-
unrecognizability.
• Mapping reducibility as a type of reducibility.
Lecture 10
• Introduction to Complexity Theory
• Complexity classes; the Class P; the Class NP
2
Time complexity
3
Intro to Complexity Theory
Example: Let 𝐴 = a! b! 𝑘 ≥ 0 .
Q: How many steps are needed to decide 𝐴?
Depends on the input.
We give an upper bound for all inputs of length 𝑛.
Called “worst-case complexity”.
4
Number of steps to decide
𝐴 = a! b! 𝑘 ≥ 0
Theorem: A 1-tape TM 𝑀 can decide 𝐴 where, on inputs of length 𝑛,
𝑀 uses at most 𝑐𝑛" steps, for some fixed constant 𝑐.
Terminology: 𝑀 uses 𝑂(𝑛") steps. Analysis:
Proof: 𝑀 = “On input 𝑤 𝑂 𝑛 steps
1. Scan input to check if 𝑤 ∈ a∗b∗, reject if not. +𝑂(𝑛) iterations
2. Repeat until all crossed off. ×𝑂(𝑛) steps
Scan tape, crossing off one a and one b. ---------------------------
Reject if only a’s or only b’s remain. 𝑂 𝑛 + 𝑂(𝑛" ) steps
3. Accept if all crossed off. ” = 𝑂(𝑛" ) steps
5
Number of steps to decide
𝐴 = a! b! 𝑘 ≥ 0
Exercise:
How much improvement is possible
in the bound for this theorem about
1-tape TMs deciding 𝐴?
(a) 𝑂(𝑛" ) is best possible.
(b) 𝑂(𝑛 log 𝑛) is possible.
(c) 𝑂(𝑛) is possible.
6
Deciding 𝐴 = a! b! 𝑘 ≥ 0 faster
𝑀 a a a a a a b b b b b b ˽
𝑀 a a a a a a b b b b b b ˽
a˽ ˽a a˽ ˽a ˽a ˽a ˽ ˽ ˽ ˽ ˽ ˽ ˽
8
Model Dependence
9
TIME Complexity Classes
# ...
TIME 2
TIME 𝑛" ...
TIME 𝑛!
TIME 𝑛 log 𝑛
Regular 𝐴
languages
10
TIME Complexity Classes
Exercice:
Let 𝐵 = 𝑤𝑤 ℛ 𝑤 ∈ a, b ∗ }.
What is the smallest function 𝑡
such that 𝐵 ∈ TIME 𝑡 𝑛 ?
(a) 𝑂(𝑛)
(b) 𝑂 𝑛 log 𝑛
(c) 𝑂(𝑛" )
(d) 𝑂 𝑛$
Multi-tape vs 1-tape time
Theorem: Let 𝑡 𝑛 ≥ 𝑛.
If a multi-tape TM decides 𝐵 in time 𝑡(𝑛), then 𝐵 ∈ TIME 𝑡 " 𝑛 .
Proof: Analyze conversion of multi-tape to 1-tape TMs.
a a b b a ˽ ˽ ...
𝑀 1 0 1 ˽ ...
...
multi-tape c c c a ˽ ...
𝑆 a a b b a # 1 0 1 # … # c c c a ˽ ˽
1-tape 𝑂 𝑡 𝑛
13
The Class P
Definition: P = ⋃! TIME(𝑛! )
= polynomial time decidable languages
• Invariant for all reasonable deterministic models
• Corresponds roughly to realistically solvable problems
𝐺
𝑠 𝑡
14
The Class P
15
𝑃𝐴𝑇𝐻 and 𝐻𝐴𝑀𝑃𝐴𝑇𝐻
16
𝑃𝐴𝑇𝐻 and 𝐻𝐴𝑀𝑃𝐴𝑇𝐻
Exercise:
Is 𝐻𝐴𝑀𝑃𝐴𝑇𝐻 ∈ P ?
(a) Definitely Yes. You have a polynomial-time algorithm.
(b) Probably Yes. It should be similar to showing 𝑃𝐴𝑇𝐻 ∈ P.
(c) Toss up.
(d) Probably No. Hard to beat the exponential algorithm.
(e) Definitely No. You can prove it!
17
Nondeterministic Complexity
...
all branches halt
18
within 𝑡(𝑛) steps
𝐻𝐴𝑀𝑃𝐴𝑇𝐻 ∈ NP
Computation of
Theorem: 𝐻𝐴𝑀𝑃𝐴𝑇𝐻 ∈ NP M on 〈𝐺, 𝑠, 𝑡〉
Proof:
“On input 〈𝐺, 𝑠, 𝑡〉 (Say 𝐺 has 𝑚 nodes.) Guess
1. Nondeterministically write a sequence bits of 𝑣$
⋮
𝑣@, 𝑣", … , 𝑣A of 𝑚 nodes.
2. Accept if 𝑣@ = 𝑠 Guess
𝑣A = 𝑡 ⋮ bits of 𝑣!
each (𝑣B , 𝑣BC@) is an edge ⋮
and no 𝑣B repeats.
3. Reject if any condition fails.” Guess
bits of 𝑣%
⋮
⋯ Check
𝑣$ , 𝑣! , … , 𝑣%
c / rej c / rej works
ac ac
𝐶𝑂𝑀𝑃𝑂𝑆𝐼𝑇𝐸𝑆 ∈ NP
Definition:
𝐶𝑂𝑀𝑃𝑂𝑆𝐼𝑇𝐸𝑆 = 𝑥 𝑥 is not prime and 𝑥 is written}
= 𝑥 𝑥 = 𝑦𝑧 for integers 𝑦, 𝑧 > 1}
Theorem: 𝐶𝑂𝑀𝑃𝑂𝑆𝐼𝑇𝐸𝑆 ∈ NP
Proof: “On input 𝑥
1. Nondeterministically write 𝑦 where 1 < 𝑦 < 𝑥.
2. Accept if 𝑦 divides 𝑥 with remainder 0.
Reject if not.”
5
Intuition for P and NP
22