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

Unit V PPT CT Part 1

The document discusses the classifications of computational problems, specifically P, NP, NP-Hard, and NP-Complete. It defines P as problems solvable in polynomial time by deterministic algorithms, NP as decision problems verifiable in polynomial time by nondeterministic algorithms, NP-Hard as problems to which all NP problems can be reduced, and NP-Complete as NP problems that are also NP-Hard. The document also provides examples of each class and highlights the open question of whether P equals NP.

Uploaded by

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

Unit V PPT CT Part 1

The document discusses the classifications of computational problems, specifically P, NP, NP-Hard, and NP-Complete. It defines P as problems solvable in polynomial time by deterministic algorithms, NP as decision problems verifiable in polynomial time by nondeterministic algorithms, NP-Hard as problems to which all NP problems can be reduced, and NP-Complete as NP problems that are also NP-Hard. The document also provides examples of each class and highlights the open question of whether P equals NP.

Uploaded by

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

P, NP, NP-Hard & NP-

complete
problems

1
Types of
• Trackable Problems
• Intrackable
• Decision
• Optimization

Trackable : Problems that can be


solvable in a reasonable(polynomial)
time.
Intrackable : Some problems are
intractable, as they grow large, we
are unable to solve them in
2
reasonable time.
Tractability
• What constitutes reasonable time?
– Standard working definition: polynomial
time
– On an input of size n the worst-case
running time is O(nk) for some
constant k
– O(n2), O(n3), O(1), O(n lg n), O(2n), O(nn),
O(n!)
– Polynomial time: O(n2), O(n3), O(1), O(n
lg n)
– Not in polynomial time: O(2n), O(nn),
O(n!)
• Are all problems solvable in 3

polynomial time?
Optimization/Decision
Problems
• Optimization Problems
– An optimization problem is one which
asks, “What is the optimal solution to
problem X?”
– Examples:
• 0-1 Knapsack
• Fractional Knapsack
• Minimum Spanning Tree
• Decision Problems
– An decision problem is one with yes/no
answer
– Examples:
• Does a graph G have a MST of weight  W?
4
Optimization/Decision
Problems
• An optimization problem tries to find an optimal
solution
• A decision problem tries to answer a yes/no question
• Many problems will have decision and optimization
versions
– Eg: Traveling salesman problem
• optimization: find hamiltonian cycle of
minimum weight
• decision: is there a hamiltonian cycle of
weight  k

5
P, NP, NP-Hard, NP-
Complete -
Definitions

6
The Class P

P: the class of 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

7
Sample Problems
in P
• Fractional
Knapsack
• MST
• Sorting
• Others?

8
The class
NP
NP: the class of decision problems that are solvable
in polynomial time on a nondeterministic machine
(or with a nondeterministic algorithm)
– (A determinstic computer is what we know)
– A nondeterministic computer is one that can “guess” the
right answer or solution
• Think of a nondeterministic computer as a
parallel machine that can freely spawn an
infinite number of processes
• 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”

9
Sample Problems in
NPKnapsack
• Fractional
• MST
• Others?
– Traveling Salesman
– Graph Coloring
– Satisfiability (SAT)
• the problem of deciding whether a
given Boolean formula is satisfiable

10
P And NP
Summary
• P = set of problems that can be
solved in polynomial time
– Examples: Fractional Knapsack, …
• NP = set of problems for which a solution
can be verified in polynomial time
– Examples: Fractional Knapsack,…, TSP,
CNF SAT, 3-CNF SAT
• Clearly P c NP
• Open question: Does P = NP?
– P ≠ NP
NP-
• What does NP-hard mean?
hard
– A lot of times you can solve a problem by reducing
it to a different problem. I can reduce Problem
B to Problem A if, given a solution to Problem A, I
can easily construct a solution to Problem B. (In
this case, "easily" means "in polynomial time.“).
• A problem is NP-hard if all problems in
NP are polynomial time reducible to
it, ...
• Ex:- Hamiltonian Cycle
Every problem in NP is reducible to
HC in polynomial time. Ex:- TSP is
B A
. Example:tolcm(m, n) = m * n /
reducible
13

gcd(m, n),
Reductio
n
• A problem R can be reduced to another
problem Q if any instance of R can be
rephrased to an instance of Q, the
solution to which provides a solution to
the instance of R
– This rephrasing is called a transformation
• Intuitively: If R reduces in polynomial
time to Q, R is “no harder to solve”
than Q
• Example: lcm(m, n) = m * n / gcd(m,
n),
lcm(m,n) problem is reduced to
NP-Hard and NP-
Complete
• If R is polynomial-time reducible to
Q, we denote this R p Q
• Definition of NP-Hard and
NP- Complete:
– If all problems R ϵ NP are
polynomial-time
reducible to Q, then Q is NP-
Hard
– We say Q is NP-Complete if Q is NP-
Hard and Q ϵ NP
• If R p Q and R is NP-Hard, Q is
15
Summar
y
• P is set of problems that can be solved
by a deterministic Turing machine in
Polynomial time.
• NP is set of problems that can be solved
by a Non-deterministic Turing Machine
in Polynomial time. P is subset of NP
(any problem that can be solved by
deterministic machine in polynomial
time can also be solved by non-
deterministic machine in polynomial
time) but P≠NP.
16
• Some problems can be translated into one
another in such a way that a fast solution
to one problem would automatically give
us a fast solution to the other.
• There are some problems that every
single
problem in NP can be translated into, and a
fast solution to such a problem would
automatically
give us a fast solution to every problem in
NP. This group of problems are known as
NP- Complete. Ex:- Clique
• A problem is NP-hard if an algorithm for
solving
it can be translated into one for solving
any NP-
problem (nondeterministic polynomial
time) problem. NP-hard therefore means
"at least as hard as any NP-problem," 17

although it might, in fact, be harder.


First NP-complete problem
— Circuit Satisfiability
(problem definition)
• Boolean combinational circuit
– Boolean combinational elements,
wired together
– Each element, inputs and outputs
(binary)
– Limit the number of outputs to 1.
– Called logic gates: NOT gate, AND gate,
OR gate.
– true table: giving the outputs for
each setting of inputs
– true assignment: a set of boolean 20

inputs.
Circuit Satisfiability
Problem:
• Circuit satisfying problem: given a
definition
boolean combinational circuit
composed of AND, OR, and NOT, is it
stisfiable?
• CIRCUIT-SAT={<C>: C is a
satisfiable boolean circuit}
• Implication: in the area of computer-
aided hardware optimization, if a
subcircuit always produces 0, then the
subcircuit can be replaced by a simpler
subcircuit that omits all gates and just 19
output a 0.
Solving circuit-
satisfiability
problem
• Intuitive solution:
– for each possible assignment,
check whether it generates
1.
– suppose the number of inputs is k,
then the total possible assignments
are 2k.
So the running time is Ω(2k). When
the size of the problem is Θ(k), then
the running time is not polynomial.
20
Limitation of Computation Power – P, NP, and NP-complete

Class P

Definition 1 Class P is a class of decision problems that can be


solved in polynomial time by (deterministic) algorithms. This class
of problems is called polynomial.

Class NP

There is a large number of important problems, for which no


polynomial-time algorithm has been found, nor has the impossibility
of such an algorithm has been proved. Some samples are:
• Knapsack problem Find the most valuable subset of n items of
given positive integer weights and values that fit into a knapsack
of a given positive integer capacity.
• Hamiltonian circuit Determine whether a given graph as a Hamiltonian
circuit (a path that starts and ends at the same vertex and passes through
all the other vertices exactly once).
• Traveling salesman Find the shortest tour through n cities with known
positive integer distances between them.
• Graph coloring For a given graph, find its chromatic number (the smallest
number of colors that need to be assigned to the graph’s vertices so that no
two adjacent vertices are assigned the same color).

3 - CNF - SAT Problem A 3 - CNF is a conjunctiv e normal form (CNF) F , which is an
AND of clauses and each of clause is the OR of 3 boolean variables from x1 / x1 , x2 / x2 ,
..., xn / xn . If there is a set of value of x1 , x2 ,..., xn such that F 1 then F is satisfiabl e,
otherwise F is unsatisfia ble. The problem is that given an F decide if F is satisfiabl e
or not.
Example of Traveling sales man problem

Given a graph G, find the shortest simple circuit (Hamiltonian


circuit) in G which passes through all the vertices.

2 Tour length
a b
8 7 3 abcda 18
5
c d abdca 11
1

Totally there are P(4,4)=4! tours.

Generally, there may have n! tours in a graph of n vertices and if


we check all the tours the computing time is O(n!).
People couldn’t find a good algorithm (using polynomial time) to
solve it!
Example of Knapsack problem

Given n items of known weights w1 , w2 ,..., wn and values v1 , v2 ,..., vn and a knapsack
of capacity W , find the most valua ble subset of the items that fit into the knapsack.
knapsack: W=10
item 1: w=7, v=$42 item 2: w=3, v=$12, item 3: w=4, v= $40, item 4: w=5, v=$25

Search for solution :


Subset  , {1},{2},{3},{4},{1,2},{1,3},{1,4},{2,3},{2,4},{3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4},{1,2,3,4}
Total wight 0, 7, 3, 4, 5, 10, 11, 12, 7, 8, 9, 14, 15, 16, 12, 19
Total value $0, $42, $12, $40, $25, $36, , , $52, $37, $65, , , , , 

Since the number of the subsets from n elements is 2 n , the computing time is O(2n ).
People couldn’t find a good algorithm (using polynomial time) to solve it !
Definition 2 A nondeterministic algorithm is a two-stage procedure that
takes as its input an instance I of a decision problem and does the
following.
• Nondeterministic (“guess”) stage: generate a candidate solution S to
the given instance I.
• Deterministic (“verification”) stage: A deterministic algorithm takes both I
and S as its input, and it outputs yes if S is a solution to instance I.

Definition 3 Class NP is the class of decision problems that that can be


solved by nondeterministic polynomial algorithms. This class of problems
is called nondeterministic polynomial.

Famous Problem: P = NP ?
Class NP-complete

Definition 3 A decision problem D1 is said to be polynomially


reducible to a decision problem D2 if there exists a function t that
transforms instances of D1 to instances of D2 such that
• t maps all yes instances of D1 to yes instances of D2 and no
instances of D1 to no instances of D2;
• t is computable by a polynomial-time algorithm.

If a problem D1 polynomially reducible to some problem D2 that


can be solved in polynomial time, then problem D1 can also be
solved in polynomial time.

Definition 4 A decision problem D is said to be NP-complete if


1. It belongs to class NP;
2. Every problem in NP is polynomially reducible to D.
Class P-complete Class P

Class NP

You might also like