Professional Documents
Culture Documents
Unit 5
Unit 5
Unit 5
3- 1
Basic Concept
Three basic concepts:
3- 2
Nondeterministic algorithms
A nondeterminstic algorithm consists of
phase 1: guessing
phase 2: checking
If the checking stage of a nondeterministic
algorithm is of polynomial time-complexity, then
this algorithm is called an NP (nondeterministic
polynomial) algorithm.
NP problems : (must be decision problems)
e.g. searching, MST
sorting
satisfiability problem (SAT)
traveling salesperson problem (TSP)
3- 3
deterministic computer which has an unlimited number of parallel
processors. A non-deterministic algorithm usually has two phases
and output steps. The first phase is the guessing phase, which
makes use of arbitrary characters to run the problem.
The second phase is the verifying phase, which returns true or
false for the chosen string. There are many problems which can be
conceptualized with help of non-deterministic algorithms including
the unresolved problem of P vs NP in computing theory.
Non-deterministic algorithms are used in solving problems which
allow multiple outcomes. Every outcome the non-deterministic
algorithm produces is valid, regardless of the choices made by the
algorithm during execution.
Advertisement
3- 4
Nondeterministic operations
and functions
Choice(S) : arbitrarily chooses one of the
elements in set S
Failure : an unsuccessful completion
Success : a successful completion
Nonderministic searching algorithm:
j ← choice(1 : n) /* guessing */
if A(j) = x then success /* checking */
else failure
3- 5
A nondeterministic algorithm terminates
unsuccessfully iff there exist no a set of choices
leading to a success signal.
The time required for choice(1 : n) is O(1).
A deterministic interpretation of a non-deterministic
algorithm can be made by allowing unbounded
parallelism in computation.
3- 6
Nondeterministic search
Nondeterministic sorting
3- 7
EXAMPLE DECISION PROBLEM
83- 8
Nondeterministic Problem
Outcome of ND Algorithm will be restricted .
3- 9
Nondeterministic Problem
Outcome of ND Algorithm will be restricted .
3- 10
NP : the class of decision problem which can
be solved by a non-deterministic polynomial
algorithm.
P: the class of problems which can be solved
by a deterministic polynomial algorithm.
NP-hard: the class of problems to which every
NP problem reduces.
NP-complete (NPC): the class of problems
which are NP-hard and belong to NP.
3- 11
Some concepts of NPC
Definition of reduction: Problem A reduces to
problem B (A B) iff A can be solved by a
deterministic polynomial time algorithm using
a deterministic algorithm that solves B in
polynomial time. B is harder.
Up to now, none of the NPC problems can be
solved by a deterministic polynomial time
algorithm in the worst case.
It does not seem to have any polynomial time
algorithm to solve the NPC problems.
3- 12
The theory of NP-completeness always
considers the worst case.
The lower bound of any NPC problem seems
to be in the order of an exponential function.
Not all NP problems are difficult. (e.g. the
MST problem is an NP problem.)
If A, B NPC, then A B and B A.
Theory of NP-completeness
If any NPC problem can be solved in polynomial
time, then all NP problems can be solved in
polynomial time. (NP = P)
3- 13
Polynamial time Exponential time
Linear search knaspsack
Binary search TSP
Insertion /quick/merge Graph colouring
MCM Sum of subset
Hamilonian cycle
Searching ,sorting,knapsack,TSP,huffman,MST,OBST
JOB sequencing,MCM,n-queen,graph colouring,
sum of subset,Hamiltonian cycle
3- 14
3- 15
X1,x2
X1=0 x2=1
X1=1 X1=0
X1 x2 x1∩x2
1 0
X2=1 X2=0
2 1
0 0
0 1
Number of input are 2
Possible outcomes are 4
Possible outcome =2^n
3- 16
Decision problems
The solution is simply “Yes” or “No”.
Optimization problems are more difficult.
3- 17
Decision problems
3- 18
The satisfiability problem
The satisfiability problem
The logical formula :
x1 v x2 v x3
& - x1
& - x2
the assignment :
x1 ← F , x2 ← F , x3 ← T
will make the above formula true .
(-x1, -x2 , x3) represents x1 ← F , x2 ← F , x3 ← T
3- 19
If there is at least one assignment which
satisfies a formula, then we say that this
formula is satisfiable; otherwise, it is
unsatisfiable.
An unsatisfiable formula :
x1 v x2
& x1 v -x2
& -x1 v x2
& -x1 v -x2
3- 20
Definition of the satisfiability problem:
Given a Boolean formula, determine
whether this formula is satisfiable or not.
A literal : xi or -xi
A clause : x1 v x2 v -x3 Ci
A formula : conjunctive normal form
C1& C2 & … & Cm
3- 21
3- 22
3- 23
3- 24
3- 25
Cook’s theorem
NP = P iff the satisfiability problem is a P
problem.
SAT is NP-complete.
It is the first NP-complete problem.
Every NP problem reduces to SAT.
3- 26
3- 27
3- 28
3- 29
3- 30
Clique Decision Problem
What is clique?
What are decision and optimization problems?
What are NP Hard Graph Problems?
Procedure to prove NP Hard
Prove CDP is NP Hard
3- 31
3- 32
3- 33
3- 34
Max clique problem
node cover :
{1, 3}
{5, 2, 4}
Decision problem : S S K
3- 40
Chromatic number decision
problem (CN)
Def: A coloring of a graph G=(V, E) is a function
f : V { 1, 2, 3,…, k } such that if (u, v) E,
then f(u)f(v). The CN problem is to determine if G
has a coloring for k.
E.g.
3-colorable
f(a)=1, f(b)=2, f(c)=1
f(d)=2, f(e)=3
e. g. A = {3, 6, 1, 9, 4, 11}
partition : {3, 1, 9, 4} and {6, 11}
3- 44
Hamiltonian cycle problem
Def: A Hamiltonian cycle is a round trip path
along n edges of G which visits every vertex
once and returns to its starting vertex.
e.g.
Hamiltonian cycle : 1, 2, 8, 7, 6, 5, 4, 3, 1.
<Theorem> SAT directed Hamiltonian
cycle ( in a directed graph )
3- 45
Traveling salesperson problem
3- 46
0/1 knapsack problem
Def: n objects, each with a weight wi > 0
a profit pi > 0
capacity of knapsack : M
Maximize pixi
1in
Subject to wixi M
1in
xi = 0 or 1, 1 i n
Decision version :
Given K, pixi K ?
1in
in poly-time.
Goal: Transform arbitrary CLIQUE instance into VC
z
z
G has m-clique (m is the numberz of clauses in E), iff E is
satisfiable.
(Assign value 1 to all variables in clique)