0% found this document useful (0 votes)
2 views

Problem Classes

ppt

Uploaded by

Ravi Varma D V S
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Problem Classes

ppt

Uploaded by

Ravi Varma D V S
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Problem Classes:

P, NP, NP-Hard and NP-Complete


Optimization & Decision
•Problems:
Decision problems: (problems with answers Yes or No)
• Given a problem and an input to the problem,
determine whether the answer is yes or no
• Optimization problems:
• Find a solution with the “best” value
• Optimization problems can be casted as a sequence of decision
problems:
Example: Shortest path: G = A weighted directed graph
• Find a shortest path from vertex x to vertex y (Optimization version)
• Does a path exist from x to y of cost at most k? (Decision version)
Class
P: • Class P consists of (decision) problems that have
polynomial time algorithms.
• Polynomial-time algorithms
• Worst-case running time is O(nk), for some constant
k>0
• Examples of polynomial time:
• O(n2), O(n3), O(1), O(n lg n), O(lgn) etc.
• Examples of non-polynomial time:
• O(2n), O(nn), O(n!)
Class NP (Nondeterministic
Polynomial)
Class NP: Consists of problems having nondeterministic
polynomial- time algorithms.
We have the following equivalent definition

• A problem is said to be in the class NP if a certificate


(candidate solution)
to the problem can be verified in (deterministic)
polynomial time.

Note that verification time ≤ time required to find a solution


Therefore, P is a subset of NP.
• Every problem in the class P is also in the class NP.
Tractable/Intractable
Problems
• Problems in P are called tractable problems
• Problems not in P are intractable problems
• Can be solved in reasonable time only for small inputs
• Or, can not be solved at all

• Are non-polynomial algorithms always worst than


polynomial algorithms?
- n1,000,000 is technically tractable, but really hard
- nlog log log n is technically intractable, may be easy to
implement
Examples of Intractable
Problems:
Examples of Intractable
Problems:
Hamiltonian
• Given: a directed Cycle
graph G = (V, E), determine a simple cycle that
contains each vertex in V
• Each vertex can only be visited once
hamiltonian
• Certificate:
• Sequence: v1, v2, v3, …, v|V|

not
hamiltonian
Is P =
NP? P

• Any problem in P is also in NP: NP

P  NP
• The big open question is whether P = NP
• If it is always easy to check a solution, should it also be easy to find a
solution?

• Most computer scientists believe that this is false but no one has
answer …
NP-Completeness
(informally) P NP-complete

NP

• NP-complete problems are

the hardest problems in NP

• Most practical problems turn out to be either P or NP-complete.


NP-
Completeness
P NP-complete
: if:
• A problem B is NP-complete
NP
(1) B is in NP

(2) B is at least as difficult as any other problem in NP


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

Note that each NP-Complete problem is an NP-Hard problem

• No polynomial time algorithm has been discovered for any NP-Complete problem

• No one has ever proven that no polynomial time algorithm can exist for any

NP-Complete problem
Is P =
NP? P NP-complete

NP

Theorem: If any NP-Complete problem can be


solved in
polynomial time, then P = NP.
P & NP-Complete
Problems
• Shortest simple path
• Given a graph G = (V, E) find a shortest path from a source to all other vertices

• This problem is in the class P

• Longest simple path


• Given a graph G = (V, E) find a longest path from a source to all other vertices

• This problem is NP-complete


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)
• Has Polynomial time solution

• Hamiltonian cycle
• G = (V, E) a connected, directed graph find a cycle that visits each vertex of G
exactly once
• NP-complete
Satisfiability Problem
(SAT)
• Satisfiability problem: given a logical expression ,
find an assignment of values (F, T) to variables xi that
causes  to evaluate to T
 =x1   x2  x3   x4

• SAT was the first problem shown to be NP-complete !


CNF
• CNF is a special case of SAT
Satisfiability
•  is in “Conjunctive Normal Form” (CNF)
• “AND” of expressions (i.e., clauses)
• Each clause contains only “OR”s of the variables and their
complements

E.g.:  = (x1  x2)  (x1   x2)  ( x1   x2)

clauses
3-CNF
A subcase of CNF problem:
Satisfiability
• Each clause contains three literals

• Example:
 = (x1  x1  x2)  (x3  x2  x4) 
(x1  x3   x4)

• 3-CNF is NP-Complete

• Interestingly enough, 2-CNF is in P !


Cliqu
Clique Problem:
e
• Undirected graph G = (V, E)
• Clique: a subset of vertices in V all connected to each other
by edges in E (i.e., forming a complete graph)
• Size of a clique: number of vertices it contains

Optimization problem: Clique(G, 2) = YES


Clique(G, 3) =
• Find a clique of maximum size NO

Decision problem:
Clique(G, 3) = YES
• Does G have a clique of size k? Clique(G, 4) = NO
Clique
Verifier
• Given: an undirected graph G = (V, E)
• Problem: Does G have a clique of size k?
• Certificate:
• A set of k nodes

• Verifier:
• Verify that for all pairs of vertices in this set there exists an edge in E

You might also like