0% found this document useful (0 votes)
17 views3 pages

(Class - 10) - NP Completeness

Gr

Uploaded by

bijayjana02
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)
17 views3 pages

(Class - 10) - NP Completeness

Gr

Uploaded by

bijayjana02
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/ 3

[Class - 10] – NP Completeness

Tractability

Some problems are intractable: as they grow large, we are unable to solve them in reasonable time.
Here, reasonable time means polynomial time.
On an input of size n the worst-case running time is O(nk) for some constant k.
Polynomial time: O(n2), O(n3), O(1), O(n lg n)
Not in polynomial time: O(2n), O(nn), O(n!)

Polynomial-Time Algorithms

Every algorithm we’ve studied so far provides polynomial-time solution to some problem. But not all
problems are solvable in polynomial time. Turing’s “Halting Problem” is not solvable by any computer, no
matter how much time is given. Most problems that do not yield polynomial-time algorithms are either
optimization or decision problems.
(The Halting Problem is this: given a Turing machine and an input to the Turing machine, does the Turing
machine finish computing in a finite number of steps (a finite amount of time)? In order to solve the
problem, an answer, either yes or no, must be given in a finite amount of time regardless of the machine
or input in question. Clearly some machines never finish. For example, we can write a Turing machine
that counts upwards starting from one.)

Optimization/Decision Problems
An optimization problem is one which asks, “What is the optimal solution to problem X?”
An optimization problem tries to find an optimal solution.

Examples:
1) 0-1 Knapsack
2) Fractional Knapsack
3) Minimum Spanning Tree

A decision problem is one which asks, “Is there a solution to problem X with property Y?”
A decision problem tries to answer a yes/no question.

Examples:
1) Does a graph G have a MST (Minimum Spanning Tree) of weight ≤ W?

Many problems will have decision and optimization versions.


Example:
1) Traveling salesman problem
2) optimization: find hamiltonian cycle of minimum weight
3) decision: find hamiltonian cycle of weight < k

Some problems are decidable, but intractable: as they grow large, we are unable to solve them in
reasonable time.

Page 1 of 3
[Class - 10] – NP Completeness
The Class P
P is the class of decision problems that have polynomial-time deterministic algorithms.
That is, they are solvable in O(p(n)), where p(n) is a polynomial on n. A deterministic algorithm is
(essentially) one that always computes the correct answer.

Some Problems those are in P:


1) Fractional Knapsack
2) MST
3) Single-source shortest path
4) Sorting

The class NP
NP is the class of decision problems that are solvable in polynomial time on a nondeterministic machine
(or with a non-deterministic algorithm). Thus NP can also be thought of as the class of problems whose
solutions can be verified in polynomial time. Note that NP stands for “Nondeterministic Polynomial
Time”.

Some problem those are in NP:


1) All problems in P are also in NP.
2) Hamiltonian Cycle (A hamiltonian cycle of an undirected graph is a simple cycle that contains every
vertex)
3) Satisfiability (SAT)
4) Conjunctive Normal Form (CNF) SAT
5) 3-CNF SAT

The Satisfiability (SAT) Problem

Given a Boolean expression on n variables, can we assign values such that the expression is TRUE?

Example: ((x1 →x2) ∨ ¬ ((¬ x1↔x3) ∨ x4)) ∧¬ x2

This problem seems simple enough, but no known deterministic polynomial time algorithm exists. But it
is very easy to verify in polynomial time.

CNF Satisfiability

Conjunctive Normal Form (CNF) and 3-CNF:


A literal is an occurrence of a Boolean or its negation. A Boolean formula is in conjunctive normal form
(CNF), if it is an AND of clauses, each of which is an OR of literals.

Example: (x1 ∨ ¬ x2) ∧ (¬ x1 ∨ x3 ∨ x4) ∧ (¬ x5)

3-CNF: In 3-CNF each clause has exactly 3 distinct literals:

Example: (x1 ∨ ¬ x2 ∨ ¬ x3) ∧ (¬ x1 ∨ x3 ∨ x4) ∧ (¬ x5 ∨ x3 ∨ x4)


Page 2 of 3
[Class - 10] – NP Completeness

Notice that it is true if at least one literal in each clause is true.

This CNF Satisfiability problem is also in NP.

P And NP Summary
P = set of problems that can be solved in polynomial time.
NP = set of problems for which a solution can be verified in polynomial time.
Clearly P is a proper subset of NP
An open question: Does P = NP?

NP-complete problems
Reduction:
A problem P can be reduced to another problem Q if any instance of P can be rephrased to an instance of
Q, the solution to which provides a solution to the instance of P.
Intuitively it can be said that if P reduces in polynomial time to Q, P is “no harder to solve” than Q.

A decision problem D is NP-complete if and only if


1. D is in NP
2. Every problem in NP is polynomial-time reducible to D.

Example:
1) Cook’s theorem is NP-complete
2) CNF-sat is NP-complete

NP-Hard and NP-Complete

If P is polynomial-time reducible to Q, we denote this P <= Q.


NP-Hard: If all problems R belongs to NP are reducible to P, then P is NP-Hard.
NP-Complete: We say P is NP-Complete if P is NP-Hard and P is in NP.

Some NP-Complete problems:


1) K-clique. (A clique is a subset of vertices fully connected to each other, i.e. a complete sub graph
of G. The clique problem: how large is the maximum-size clique in a graph? Is there a clique of size
k?)
2) 0-1 knapsack: when weights not just integers.
3) Hamiltonian path. (A Hamiltonian path is a graph path between two vertices of a graph that visits
each vertex exactly once)
4) Graph coloring. (Can a given graph be colored with k colors such that no adjacent vertices are the
same color?)

Page 3 of 3

You might also like