P/NP
CSE 332 – Section 10
P/NP
An alternate diagram of P/NP
NP
NP Complete
NP Hard
Sorting
Shortest Path
Euler Path
Vertex Cover
Independent Set
Hamiltonian Path
Halting Problem
N x N Chess
If P = NP, everything in the green bubble is actually P!
P
One more diagram of P/NP
difficulty
NP-Complete
P
NP-Hard
NP-Intermediate
EXP
If P = NP, the gap between yellow and red lines collapse!
P, NP, NP-Complete
Complexity Classes (Question 0)
Complexity Classes (Question 0)
P, NP, NP-Complete
P & NP Membership (Question 1)
P & NP Membership (Question 1)
P & NP Membership (Question 2)
P, NP, NP-Complete
Algorithm: For each point, find its distance to every other point. If the distance is ever less than 5, return true. After doing this for all points, return false.
Running time: O(n^2)
Problem A is in P
P, NP, NP-Complete
Verification Algorithm: Given a candidate pair of points, verify that those points are both in the list, then verify that their distance is less than 5.
Running time: O(n)
Problem A is in NP
P, NP, NP-Complete
Algorithm: Sort the list, then check if any two neighboring items match.
Running time: O(n log n)
Problem B is in P
P, NP, NP-Complete
Verification Algorithm: Given a candidate value, check that the value appears at least twice in the list.
Running time: O(n)
Problem B is in NP
P, NP, NP-Complete
Verification Algorithm: Given a candidate path, check that it is a valid path (all adjacent nodes in the path form edges in the graph), and check that the sum of those edge weights is at least the value k.
Running time: O(V + E)
Problem C is in NP
P, NP, NP-Complete
NP-Hard, NP-Complete (Question 3)
P, NP, NP-Complete
NP-Hard, NP-Complete
P, NP, NP-Complete
NP-Hard, NP-Complete (Question 4)
P, NP, NP-Complete
NP-Hard, NP-Complete
P, NP, NP-Complete
Reduction
Reductions Visual
Reduction
n^p work to relate Problem A input
to Problem B input
n^p work to relate Problem B output to Problem A output
Solution for A
Solution for B
“A polynomial time reduces to B”
P, NP, NP-Complete
Sorting Problem:
Min Hamiltonian Path Problem:
We want to reduce Sorting Problem to Min Hamiltonian Path Problem
Example: Hamiltonian Sort
P, NP, NP-Complete
Example: Hamiltonian Sort
P, NP, NP-Complete
Example: Construct Graph
P2
P1
P3
distance(P2, P3) = | a3-a2 |
distance(P2, P1)
distance(P1, P3)
P, NP, NP-Complete
Example: Create Vertices
(1, 0)
(2, 0)
(7, 0)
(4, 0)
P, NP, NP-Complete
Example: Construct Edges
(1, 0)
(2, 0)
(7, 0)
(4, 0)
6
1
3
2
3
5
P, NP, NP-Complete
Example: Compute path
(1, 0)
(2, 0)
(7, 0)
(4, 0)
6
1
3
2
3
5
P, NP, NP-Complete
Example: Sorted List
(1, 0)
(2, 0)
(7, 0)
(4, 0)
6
1
3
2
3
5
P, NP, NP-Complete
Example: Compare difficulty
P, NP, NP-Complete
Reductions and NP-Hard
P, NP, NP-Complete
NP-Complete
P, NP, NP-Complete
Practice - True/False
P, NP, NP-Complete
Practice - True/False
False
True
False
True
False
False
False
False
True
Thank You!