0% found this document useful (0 votes)
28 views27 pages

NP Complete

Uploaded by

CHIRAG KUMARCk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views27 pages

NP Complete

Uploaded by

CHIRAG KUMARCk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

NP-Complete

Polynomial Time

• Most (but not all) of the algorithms we have studied so far are easy, in
that they can be solved in polynomial time, be it linear, quadratic, cubic,
etc.

• Cubic may not sound very fast, and isn’t when compared to linear, but
compared to exponential we have seen that it has a much better
asymptotic behavior.

• There are many algorithms which are not polynomial. In general, if the
space of possible solutions grows exponentially as n increases, then we
should not hope for a polynomial time algorithm. These are the
exception rather than the rule.
Hard Problems

• Problems with no known polynomial solution are called Hard problems.


• Another class of problems (NP) seem like they should be easy. They
have the following property:
1. A solution can be verified in polynomial time.
• Consider the following very common example called Satisfiability:
(SAT)
• Input: A Boolean expression, F, over n variables (x1,. ..,xn)
• Output: 1 if the variables of F can be fixed to values which
make F equal true; 0 otherwise.
• The CNF-satisfiability problem is a version of the Boolean satisfiability
problem, where the Boolean formula is specified in the conjunctive
normal form (CNF), i.e., a conjunction of clauses, where each clause is a
disjunction of literals, and a literal is a variable or its negation.
• K-CNF : Each clause has exactly K literals.
NP Complete

• Informally, a problem is in the class NPC—and we refer to it as being NP


complete—if it is in NP and is as “hard” as any problem in NP.

• If any NP-complete problem can be solved in polynomial time, then every


problem in NP has a polynomial time algorithm.

• When we demonstrate that a problem is NP-complete, we are making a


statement about how hard it is (or at least how hard we think it is), rather than
about how easy it is. We are not trying to prove the existence of an efficient
algorithm, but instead that no efficient algorithm is likely to exist.

• We rely on three key concepts in showing a problem to be NP-complete:


1.Decision problems vs. optimization problems
2.Reduction
3.A first NP-Complete Problem
Decision problems vs. optimization problems

• Optimization problems – problems in which feasible (i.e.,


“legal”) solution has an associated value, and we wish to
find a feasible solution with the best value.
• Example: SHORTEST-PATH problem, given an undirected
graph G and vertices u and v, and we wish to find a path
from u to v that uses the fewest edges. In other words,
SHORTEST-PATH is the single-pair shortest-path problem
in an unweighted, undirected graph.
Decision problems vs. optimization problems

• Decision problems - problems in which the answer is simply


“yes” or “no” (or, more formally, “1” or “0”).
• NP completeness applies directly not to optimization problems,
• However, there is a convenient relationship between
optimization problems and decision problems.
• We usually can cast a given optimization problem as a related
decision problem by imposing a bound on the value to be
optimized.
• For example, a decision problem related to SHORTEST-PATH
is PATH: given a directed graph G, vertices u and v , and an
integer k, does a path exist from u to v consisting of at most k
edges?
Decision problems vs. optimization problems

• If an optimization problem is easy, its related decision problem


is easy as well.
• In other way, we can say that if we can provide evidence that a
decision problem is hard, we also provide evidence that its
related optimization problem is hard.
• Thus, even though it restricts attention to decision problems, the
theory of NP-completeness often has implications for
optimization problems as well.
Reductions

Let us consider a decision problem A, which we would like to solve in polynomial


time. We call the input to a particular problem an instance of that problem; for
example, in PATH, an instance would be a particular graph G, particular vertices u
and v of G, and a particular integer k. Now suppose that we already know how to
solve a different decision problem B in polynomial time.
Let there is a procedure that transforms any instance α of A into some instance β of
B with the following characteristics:
1. The transformation takes polynomial time.
2. The answers are the same. That is, the answer for α is “yes” if and only if the
answer for β is also “yes.”
such a procedure a polynomial-time reduction algorithm.
Reductions
NP Problems

• NP stands for non-deterministic polynomial time.


• The NP problems are set of problems whose solutions are hard to find
but easy to verify and are solved by Non-Deterministic Machine in
polynomial time.
• The basic premise is we could guess at a solution and then test whether
we guessed right or not easily. Guessing is of course non-deterministic!
• So, think of this as guessing in polynomial time. No guarantee that you
will ever guess correctly though.
NP-Complete

• A problem X is NP-Complete if there is an NP problem Y, such that Y is


reducible to X in polynomial time. NP-Complete problems are as hard as
NP problems. A problem is NP-Complete if it is a part of both NP and NP-
Hard Problem. A non-deterministic Turing machine can solve NP-
Complete problem in polynomial time.
NP-Hard

• A Problem X is NP-Hard if there is an NP-Complete problem Y, such that


Y is reducible to X in polynomial time. NP-Hard problems are as hard as
NP-Complete problems. NP-Hard Problem need not be in NP class.
Polynomial Time Reductions

• The SAT problem is a circuit, so it is very useful and interesting. Can we


write a program to do X? This and many other problems have been
studied at length.
• There are many mappings (called reductions) that have been
discovered that map one problem to the other, so if we solve one we can
solve the other.
• Moreover, these mappings are polynomial time mappings.
NP-Complete

• The set of NP problems that can be mapped to each other in polynomial


time is called NP-Complete.
• It is difficult to prove that something can not be done.
• Let me repeat that, it is difficult to prove that something can not be done.
• So, while we know how to solve many of these algorithms in exponential
time, whose to say that one of you bright students won’t come up with a
clever polynomial time algorithm!
• NP-Complete is useful from that standpoint, if any of them turns out to
have a polynomial time algorithm, they all do (hence P=NP).
• Of course, us old professors feel that these problems have been looked
at from every angle and no such solution will ever be found (hence, P ≠
NP).
NP-Complete

• It is also useful to know these algorithms, as they


occur frequently in real applications and tackling them
in a brute force fashion may be disastrous.
• SAT problem
• Traveling Salesman problem
• Knapsack Problem
• Longest Path
• Graph Clique
TSP

2
i = 23
2
1 1 3
4 1
3
5 4
4 2
1 2 2 2
2 1
1

• For each two cities, an integer cost is given to travel from


one of the two cities to the other. The salesperson wants
to make a minimum cost circuit visiting each city exactly
once.
Circuit-SAT

Logic Gates 0 1 0
1 1
NOT
1 1
0
OR 1
0 0 1
1

AND

• Take a Boolean circuit with a single output node


and ask whether there is an assignment of
values to the circuit’s inputs so that the output is
“1”
Unweighted Bipartite Matching
Definitions

Matching

Free Vertex
Definitions

• Maximum Matching: matching with the largest number of edges


Definition

• Note that maximum matching is not unique.


Intuition

• Let the top set of vertices be men


• Let the bottom set of vertices be women
• Suppose each edge represents a pair of man and woman who like each
other

• Maximum matching tries to maximize the number of couples!


Graph Clique

• Set of vertices
such that they
all connect
to each
other.
K-Cliques
• A K-clique is a set of K nodes with all K(K-1)/2 possible edges between
them

This graph contains a 4-clique


K-Cliques

• Given: (G, k)
Question: Does G contain a k-clique?

• BRUTE FORCE:
• Try out all {n choose k} possible locations for the k clique
NP-Complete

• It is also interesting to look at the relationship between some easy


problems and hard ones:

Hard Problems Easy Problems


(NP-Complete) (in P)
SAT, 3SAT 2SAT

Traveling Salesman Problem Minimum Spanning Tree

3D Matching Bipartite Matching

Knapsack Fractional Knapsack

You might also like