Analogy (sort of)
Lord of The Rings
“One ring to rule them all”
“my preciousss…”
Computational Complexity
“One problem to solve them all”
“my preciousss…”
NP Complexity
The class NP consists of all problems that can be solved
in polynomial time by nondeterministic algorithms
Nondeterministic algorithms are done in two phases:
•Phase I: algorithm that makes a guess (solutions must be
included among the possible guesses)
•Phase II: algorithm that checks if the guess is an actual
solution or not
The Traveling Salesperson Problem (TSP)
Given the cities and cost to travel between cities, obtain a
route R such that:
1. All cities are in R
2. Every city is visited only once in R
3. R has the minimum cost. That is, for any other route R’
meeting 1-2, cost(R’) cost(R).
Example: Traveling Salesman
Problem (TSP) is in NP
10
B
H
16
9
12
A 4
20
G
C
8
24
6
13
D
6
F
E
20
Proof
We can show that Traveling Salesman Problem (TSP) is in NP
phaseI(G: Graph)
//input: G a graph with n nodes
//output: C a guess for TSP
phaseII(C: path, min: int )
//input: C a guessed solution
//output: true iff C is a TSP
v randomNode(G)
C ()
While random(0,1) = 1
and |C| < n do {
w PickNeighbourRandomly(v)
C C + (v,w)
vw
}
return C
If |C| < n then return false
Visited {}
for i =1 to n do {
(u,v) = C[i]
if v in Visited then
return false
else Visited Visited + {v}
}
return cost(C) = min
Why do We Care About NP Problems?
Network Problems
Data Storage
Scheduling
Mathematical
Programming
•Traveling Salesperson
•Longest path
•Graph coloring
•Minimum Bin Packing
•Minimum Job Scheduling
•Minimum Multiprocessor Scheduling
•Knapsack
Why do We Care About NP Problems? (II)
Automata Theory
(computing)
Planning
•Longest computation
•Shortest computation
•Find a Universal Problem Solver
All of these problems have 4 things in common:
•They are important for a group of people
•No knows (for sure) if they are in P or not
•All of them are in NP
•They all are in a special category of NP problems: NPComplete problems
NP-Complete
A problem npc is NP-complete if:
• npc is in NP
• Every other problem prob in NP can be transformed
in polynomial time into npc. (NP-Hard)
Reduction:
prob
Polynomial
transformation
solution
npc
NP-Complete
TSP
MST
Shortest Path
npc
Sorting
…
Knapsack
“my preciousss…”
1. If we can find one NP-complete problem the can be solved in
polynomial time then P = NP
2. If we can show for one NP-complete problem that it cannot be
solved in polynomial time then no other NP-complete problem
can be solved in polynomial time (and P ≠NP)
Fine, But How Do one Proof that a Problem
is NP-Complete?
• First problem was hard to proof: Conjunctive Normal
Form (Cook, 1971)
• Every problem q afterwards is “easier”:
Show that q is in NP
Find a problem, npc, that is NP-complete and show that
npc can be transformed in polynomial time into q
TSP
Shortest Path
Sorting
MST
npc
q
…
Knapsack
Conjunctive Normal Form
A conjunctive normal form (CNF) is a Boolean expression
consisting of one or more disjunctive formulas connected by an
AND symbol (). A disjunctive formula is a collection of one or
more (positive and negative) literals connected by an OR
symbol ().
Example:
(a) (¬ a ¬b c d) (¬c ¬d) (¬d)
Problem (CNF-satisfaction): Give an algorithm that
receives as input a CNF form and returns Boolean
assignments for each literal in form such that form is true
Example (above):
a true, b false, c true, d false
Cook Theorem (1971)
The CNF-satisfaction satisfaction is NP-complete
© Copyright 2025 Paperzz