Week 14 15
Week 14 15
Shahid Hussain
Weeks 14 and 16: November 18 - November 27, 2024: Fall 2024
1
Computational Complexity
Decision Problems vs Optimization Problems
Decision Problem
A computational problem is called decision problem if the answer is either yes
or no. For example:
• Is there a path of length k in a graph G?
• Is a given array A sorted in non-decreasing order?
Optimization Problem
A computational problem is called optimization problem if the answer is a value
that needs to be maximized or minimized. For example:
• Find the shortest path between two nodes in a graph G.
• Find the minimum spanning tree of a graph G.
2
Computational Complexity
3
Model of Computation
4
Languages and Decision Problems
Language
A language is a set of strings over a finite alphabet (Σ) For example, the set of all
binary strings that represent prime numbers is a language
5
Algorithms and Machines
6
The Class P
The class P
The class P contains all languages (decision problems) which can be decided by
some polynomial time algorithm i.e., the membership queries can be computed in
polynomial time by some algorithm
7
The Class NP
The word β is called the certificate and the algorithm which computes the
predicate Q is called the verifier.
8
The Classes P and NP
Theorem
P ⊆ NP.
Proof.
• Let L ∈ P, L ⊆ Σ∗ , and q(n) = 1
• Let us consider a predicate Q(α, β) such that Q(α, β) = 1 if and only if α ∈ L
• Since L ∈ P, the predicate Q is a polynomial time predicate
• It is clear that α ∈ L if and only if there exists β ∈ Σ∗ such that |β| ≤ 1 and
Q(α, β) = 1 (we can take β = ϵ)
9
Reduction
Proposition
1. If L1 ≤P L2 and L2 ∈ P then L1 ∈ P.
2. If L1 ≤P L2 and L1 ̸∈ P then L2 ̸∈ P.
3. If L1 ≤P L2 and L2 ≤P L3 then L1 ≤P L3 . (Transitivity property.)
10
NP-hard and NP-complete Problems
NP-hard problems
A language L is NP-hard if for all L′ ∈ NP, we have L′ ≤P L.
NP-complete problems
A language L is NP-complete if L ∈ NP and L is NP-hard.
11
Boolean Functions and CNF
Boolean Function/Formula
A function f : {0, 1}n → {0, 1} is called a boolean function of n variables.
where each Cj is a clause of the form lj1 ∨ lj2 ∨ . . . ∨ ljk and each lji is a literal
which is either a variable xi or its negation ¬xi
• We assume that each variable occurs in each clause Cj at most once
12
Satisfiability Problem
Satisfiability Problem
Decision Problem: sat
Setup: A boolean formula f of n variables in CNF
Question: Is there an assignment of values to the variables such that f evaluates
to true?
13
Satisfiability Problem is in NP
14
Satisfiability Problem is NP-hard
• This proof was independently discovered by Stephen Cook (in United States)
and Leonid Levin (in, then, Soviet Union) in 1971
• This proof laid down the theoretical/mathematical foundation of the theory of
NP-complete problems
• In the subsequent we present some NP-complete problems all of which can
proved to be NP-hard using the polynomial time reduction (due to transitivity
property of reduction)
15
The 3 SAT problem
• 3sat ∈ NP (trivial)
• sat ≤P 3sat (left as an exercise)
16
Independent Set Problem
17
Independent Set Problem
18
Proving Independent Set to NP-complete
19
Showing Independent Set is in NP
20
Showing Independent Set is NP-hard
21
Example Reduction
¬x2 ¬x1 x1
x1
x3 ¬x3 x3
22
Vertex Cover Problem
23
Vertex Cover Problem
24
Proving Vertex Cover is NP-complete
– Vertex cover
– Independent set
26
Set Cover Problem
a1 a2 a3 S1
a4 a5 a6
S2 S3 S4
27
Set Cover Problem
• Thus, sc is NP-complete
28
Set Cover Problem
d
2 4
a h
e g
1 c 6
b 3 5
k
f
• The set cover problem UG , FG for the above graph G = (V, E) is:
• UG = {a, b, c, d, e, f, g, h, k}
• FG = {S1 , S2 , S3 , S4 , S5 , S6 }
• S1 = {a, d}, S2 = {a, c}, S3 = {d, e}, S4 = {d, h}, S5 = {e, g}, S6 = {h, k}
29