TOPICS IN ALGORITHMS
http://eclass.aueb.gr/courses/INF171/
Spring 2017
I. ΜILIS
P, NP and NP-COMPLETE
PROBLEMS
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
1
Complexity Class P
All problems for which there exists an algorithm
of O(poly) worst case complexity
O(poly) means polynomial in |I|, i.e., O(poly( |I| ) )
Problems in P: MIN, MAX: O(n)
SORTING: O(n log n)
INTEGER MULTIPLICATION: O(n1.59)
GCD(a,b), a>b: O(log a)
PRIMES: O (log 12 n) [ August 2002] !
… many other …
Problems without an O(poly) algorithm:
SUBSET SUM : O(nB)
SAT: O(2n)
… many other too…
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
2
Decision and Optimization Problems
Decision problems: problems with answer YES or NO
e.g. PRIMES, SUBSET SUM, SAT, SEARCH, …
Optimization problems: maximize/minimize some objective function
TSP (Traveling Salesman Problem)
I: A complete weighted digraph G = (V, E)
Q: Find a minimum length tour of G
(tour: a cycle visiting each node once)
CLIQUE
I: A graph G=(V,E)
Q: Find the maximum subset C Í V s. t. " u,v Î C: (u,v) Î E
(the maximum complete subgraph of G)
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
3
Decision and Optimization Problems
An optimization problem has three versions/questions:
Function version: find an optimal feasible solution
Evaluation version: find the cost of an optimal feasible solution
Decision version: Given a bound B, is there a feasible solution
of cost £ B (for minimization problems) or
of cost ≥ B (for maximization problems)
TSP
Q1: Find a tour of minimum cost
Q2: Find the cost of a minimum tour
Q3: Is there a tour of cost £ B ?
CLIQUE
Q1: Find the vertices of C
Q2: Find the size of C
Q3: Is there C Í V such that " u,v Î C: (u,v) Î E and |C| ³ B ?
For any optimization problem we can state its decision version
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
4
Decision and Optimization Problems
For any optimization problem we can state its decision version
In the following we consider ONLY decision problems or
the decision version of optimization problems !
§ they can be encoded as languages
§ they are used to define complexity classes
§ the decision version of an optimization problem is equivalent to
its function and evaluation versions !
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
5
Decision and Optimization Problems
For all the problems you have seen and will see:
Given an algorithm for the decision version of an optimization problem,
there exists a polynomial time algorithm to answer both its evaluation
and function versions
Example: TSP
(1)
Q3 à Q2
Let C* the cost of an optimal solution
Then, 0 £ C* << 2|I|
Apply the question "is there a tour of cost £ B" for several
values of B
For what values of B ? (not for all)
Apply binary search
Complexity O(log2|I|) = O(|I|), polynomial.
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
6
Decision and Optimization Problems
Example: TSP (cont.)
(2)
Q3 à Q1
Find C* as in (1)
T:= { } // T stores an optimal tour
For each edge e Î E do
{ x :=w(e);
w(e) := w(e) + M; // M is some positive number
"is there a tour of cost £ C* ? "
if NO then
{ T=T U {e} ;
// e is in an optimal tour;
w(e):=x }
// restore the weight of e;
// if YES then e is not in any optimal tour;
// keep its weight to w(e) + M
Complexity O(|E|) ~ O(n2)
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
7
Complexity Class NP
For a decision problem Π, an instance Ι Î Π is a
• yes-instance, if there exists a solution to the question posed by Π
• no-instance, otherwise
Definition (high level):
• A problem Π is in NP if we can verify efficiently the validity of a
candidate solution
• i.e., we can convince somebody for a yes-instance in poly-time
In TSP: a candidate solution (a certificate) = one of the possible tours
Definition (formal):
A problem Π Î NP iff for every yes-instance Ι of Π,
there is a polynomial time verification algorithm A,
and a certificate x with |x| ≤ poly(|I|), such that A(I, x) = yes
All problems for which there is a non-deterministic O(poly) algorithm
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
8
Complexity Class NP
A problem Π Î NP iff
for each instance of Π with answer YES
there is an O(poly) validation algorithm
Verification of yes-instances is not the same as distinguishing between
yes/no instances
Example: TSP
§ yes-instance: certificate x = a collection of edges
(expected to be a tour)
Verification algorithm:
check if it is a tour;
evaluate its cost;
check if its cost £ B ; O(n) time in total
§ no-instance: the only way to convince someone for a no-instance
of TSP would be to check all tours !
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
9
P and NP
If for a problem we have an O(poly) algorithm that solves it
we can, obviously, validate a YES instance in O(poly) time
Hence: P Í NP
P
NP
What about the reverse direction? Million dollar question!!
http://www.claymath.org/millennium-problems
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
10
Polynomial Reductions
A, B: decision problems
•
•
We say that A polynomially reduces to B (A £p B) if
there is a polynomial time transformation R such that:
§ for every instance Ι Î A, it produces an instance R(I) Î B
§ I is a yes-instance for A iff R(I) is a yes-instance of B
i.e. the answer to B with input R(I) is YES
iff the answer to A with input x is YES
In other words: to solve A on input x we just have to:
Þ compute R(x)
Þ solve B on R(x)
O(poly) for R(x) + O(poly) algorithm for B = O(poly) algorithm for A
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
11
Polynomial Reductions
An algorithm for A
A polynomial time reduction from A to B
shows that A is not more difficult than B
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
12
Complexity Class NP-complete
A problem Π Î NP is NP -complete iff
for every other problem Π' Î NP : Π' £p Π
ΝP-complete:
• captures the essence and the difficulty of NP
• identifies the most difficult problems in NP
Recall P Í NP
What is the map of NP ?
THE question in TCS !
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
13
Complexity Class NP-complete
The common belief
Not possible
(Ladner’s theorem)
Nobody believes this
No O(poly) algorithm is known for any NP -complete problem.
If you ever derive one you will have proven that P = NP !
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
14
Complexity Class NP-complete
Prove that Π is NP -complete:
1. prove that Π Î NP
2. prove that " Π' Î NP : Π' £p Π
???
Fortunately we have the
Cook's Theorem [Cook 1970, Levin 1972]:
SAT is NP –Complete (for every Π' Î NP : Π' £p SAT)
and since £p ’s can be composed, proving that Π is NP -complete
requires:
1. prove that Π Î NP
2. prove that $ Π' Î NP –complete s.t. Π' £p Π
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
15
Tree of reductions (partial)
" Π Î NP
Cook
SAT
3-SAT
MAX 2-SAT
3- GC
CLIQUE / IS / VC
HP / HC
3-DM / X3C
0-1 KNAPSACK
TSP / Δ -TSP
Let Π be a problem, G a generalization of Π, and S a special case of Π
§ G is polynomial è Π is polynomial è S is polynomial
§ S is NP -complete è Π is NP -complete è G is NP -complete
AUEB / DoI / TOPICS IN ALGORITHMS / Spring 2017 / I. MILIS / 02 - NP
16
© Copyright 2026 Paperzz