0% found this document useful (0 votes)
34 views36 pages

Np-Hard and Np-Complete Problems

ppt for unit-5 in daa

Uploaded by

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

Np-Hard and Np-Complete Problems

ppt for unit-5 in daa

Uploaded by

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

NP–HARD AND NP-COMPLETE

PROBLEMS
Dr K Shahu Chatrapati
Deterministic Algorithms
• A deterministic algorithm is an algorithm which,
given a particular input, will always produce the
same output, with the underlying machine always
passing through the same sequence of states.
• Formally, a deterministic algorithm computes a
mathematical function; a function has a unique
value for any input in its domain, and the
algorithm is a process that produces this particular
value as output.
Nondeterministic Algorithms
• A nondeterministic algorithm is an algorithm
that, even for the same input, can exhibit
different behaviors on different runs, as
opposed to a deterministic algorithm.
• The nondeterministic algorithms are often
used to find an approximation to a solution,
when the exact solution would be too costly
to obtain using a deterministic one.
Nondeterministic Search

Time Complexity of nondeterministic search is O(1)


Nondeterministic Sorting

Time complexity of nondeterministic sorting is O(n)


Decision Problem Vs. Optimization Problem

• Any problem for which the answer is


either zero or one is called a decision
problem.
• An algorithm for a decision problem is
termed a decision algorithm.
• Example: Whether given number is
prime or not.
• Any problem that involves the
identification of an optimal (either
minimum or maximum) value of a given
cost function is known as an
optimization problem.
• An optimization algorithm is used to
solve an optimization problem
Decision Problems Vs. Optimization Problems

• Many optimization problems can be recast


into decision problems with the property that
the decision problem can be solved in
polynomial time if and only if the
corresponding optimization problem can.
• In other words, if the decision problem cannot
be solved in polynomial time, then the
optimization problem cannot either
Example: Maximum Clique
• A maximal complete subgraph of a graph G=(V,E)
is a clique. The size of the clique is the number of
vertices in it.
• The max clique problem is an optimization
problem that has to determine the size of a largest
clique in G.
• The corresponding decision problem is to
determine whether G has a clique of size at least k.
• Let DClique(G,K) be a deterministic decision • If the size of a max clique can
algorithm. be determined in time g(n),
then the decision problem
• If the number of vertices in G is n, the size of a max
can be solved in time g(n).
clique in G can be found by making several
applications of DClique, once for each k=n,n-1,n-2, • In other words, the max
…, until the output from DClique is 1. clique problem can be solved
• If the time complexity of DClique is f(n), then the in polynomial time if and
size of the max clique can be found in time less only if the clique decision
than or equal to n*f(n). problem can be solved in
polynomial time
Example: 0/1 Knapsack Decision Problem
Satisfiability Problem (SAT)
Given a logical expression , find an assignment of values (False, True) to variables x i that causes  to evaluate to True
 =x1   x2  x3   x4

10
Nondeterministic Clique Algorithm
Nondeterministic Knapsack’s Algorithm
Nondeterministic Satisfiability
Algorithmic vs Problem Complexity
• The algorithmic complexity of a computation is
some measure of how difficult is to perform the
computation (i.e., specific to an algorithm)
• The complexity of a computational problem or
task is the complexity of the algorithm with the
lowest order of growth of complexity for solving
that problem or performing that task.
– e.g. the problem of searching an ordered list has at
most O(log n) time complexity.
• Computational Complexity: deals with classifying
problems by how hard they are.

14
Class of “P” Problems
• Class P consists of (decision) problems that are
solvable in polynomial time
• Polynomial-time algorithms
– Worst-case running time is O(nk), for some constant k
• Examples of polynomial time:
– O(n2), O(n3), O(1), O(n lg n)
• Examples of non-polynomial time:
– O(2n), O(nn), O(n!)

15
Tractable/Intractable Problems
• Problems in P are also called tractable
• Problems not in P are intractable or unsolvable
– Can be solved in reasonable time only for small
inputs
– Or, can not be solved at all

16
Examples of Intractable Problems

17
Intractable Problems
• Can be classified into various categories based
on their degree of difficulty, e.g.,
– NP
– NP-complete
– NP-hard
• Let’s define NP algorithms and NP problems …

18
Nondeterministic and NP Algorithms

Nondeterministic algorithm = two stage procedure:


1) Nondeterministic (“guessing”) stage:
generate randomly an arbitrary string that can be
thought of as a candidate solution (“certificate”)
2) Deterministic (“verification”) stage:
take the certificate and the instance to the problem
and returns YES if the certificate represents a solution
NP algorithms (Nondeterministic polynomial)
verification stage is polynomial
19
Class of “NP” Problems
• Class NP consists of problems that could be
solved by NP algorithms
– i.e., verifiable in polynomial time

• If we were given a “certificate” of a solution,


we could verify that the certificate is correct in
time polynomial to the size of the input
• Warning: NP does not mean “non-polynomial”
20
Is P = NP?
• The P versus NP problem is a major unsolved
problem in computer science.
• It asks whether every problem whose solution P
can be quickly verified can also be solved NP
quickly. That is whether P=NP or P ≠ NP.
• Since deterministic algorithms are just a
Commonly believed
special case of nondeterministic ones, we relationship between
conclude that P⊆NP. That is, any problem
P and NP

in P is also in NP:

21
NP-Completeness (informally)
P NP-complete
• NP-complete problems are
NP
defined as the hardest
problems in NP
• Most practical problems turn out to be either P
or NP-complete.
• Study NP-complete problems …

22
Reductions
• Reduction is a way of saying that one problem is
“easier” than another.
• We say that problem A is easier than problem B,
(i.e., we write “A  B”)
if we can solve A using the algorithm that solves B.
• Idea: transform the inputs of A to inputs of B

yes
yes
 
f Problem B no
no
Problem A
23
Polynomial Reductions

• Given two problems A, B, we say that A is

polynomially reducible to B (A p B) if:

1. There exists a function f that converts the input of

A to inputs of B in polynomial time

2. A(i) = YES  B(f(i)) = YES


24
NP-Completeness (formally)
P NP-complete
• A problem B is NP-complete if:

(1) B  NP NP

(2) A p B for all A  NP

• If B satisfies only property (2) we say that B is NP-hard

• No polynomial time algorithm has been discovered for an NP-


Complete problem
• No one has ever proven that no polynomial time algorithm can
exist for any NP-Complete problem

25
Implications of Reduction
yes
yes
 
f Problem B no
no
Problem A

- If A p B and B  P, then A  P

- if A p B and A  P, then B  P

26
Proving Polynomial Time
yes
yes
  Polynomial time
f algorithm to decide B no
no
Polynomial time algorithm to decide A

1. Use a polynomial time reduction algorithm to


transform A into B
2. Run a known polynomial time algorithm for B
3. Use the answer for B as the answer for A

27
Proving NP-Completeness In Practice

• Prove that the problem B is in NP


– A randomly generated string can be checked in
polynomial time to determine if it represents a
solution
• Show that one known NP-Complete problem can
be transformed to B in polynomial time
– No need to check that all NP-Complete problems are
reducible to B

29
Revisit “Is P = NP?”
P NP-complete

NP

Theorem: If any NP-Complete problem can be


solved in polynomial time  then P = NP.

30
P & NP-Complete Problems
• Shortest simple path
– Given a graph G = (V, E) find a shortest path from a source
to all other vertices
– Polynomial solution: O(VE)

• Longest simple path


– Given a graph G = (V, E) find a longest path from a source
to all other vertices
– NP-complete

31
P & NP-Complete Problems
• Euler tour
– G = (V, E) a connected, directed graph find a cycle that
traverses each edge of G exactly once (may visit a vertex
multiple times)
– Polynomial solution O(E)
• Hamiltonian cycle
– G = (V, E) a connected, directed graph find a cycle that
visits each vertex of G exactly once
– NP-complete

32
NP-naming convention
• NP-complete - means
problems that are
'complete' in NP, i.e.
the most difficult to
solve in NP
• NP-hard - stands for
'at least' as hard as NP
(but not necessarily in
NP);

33
Examples NP-complete and
NP-hard problems

NP-complete

NP-hard

34
Why should we care?
• Knowing that they are hard lets you stop beating
your head against a wall trying to solve them…
– Use a heuristic: come up with a method for solving a
reasonable fraction of the common cases.
– Solve approximately: come up with a solution that
you can prove that is close to right.
– Use an exponential time solution: if you really have
to solve the problem exactly and stop worrying about
finding a better solution.

35
COOK’S Theorem
• Cook’s theorem states that the Boolean satisfiability
problem is NP-complete.
• That is, any problem in NP can be reduced in polynomial
time to the problem of determining whether a Boolean
formula is satisfiable.
• An important consequence of this theorem is that if there
exists a deterministic polynomial time algorithm for solving
Boolean satisfiability, then every NP problem can be solved
by a deterministic polynomial time algorithm.
• The question of whether such an algorithm for Boolean
satisfiability exists is thus equivalent to the P vs. NP
problem, which is widely considered the most important
unsolved problem in theoretical computer science.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy