Unit 5
Unit 5
computing times for Choice, Success and Failure are taken to be O(1). Nondeterministicmachines
provide strong intuitive reasons to conclude that fast deterministic algorithmscannot solve certain
problems.
Example 1: Sorting: -
It sorts the numbers into ascending order and then outputs them in this order. Anauxiliary array
B[1:n] is used for convenience. Line 4 initializes B to zero. In the
for
loopof lines 5 to 10, each A[i] is assigned to a position in B. Line 7 non-
deterministicallydetermines this position. Line 8 makes sure that B[j] has not already been
used. Thus, theorder of the numbers in B is some permutation of the initial order in A.
The
for
loop of lines 11 and 12 verifies that B is sorted in ascending order. A successful
completion isachieved if and only if the numbers are output in nondecreasing order.
Since there isalways a set of choices at line 7 for such an output order, algorithm
Nsort is a sortingalgorithm. Its complexity is O(n). Recall that all deterministic
sorting algorithms musthave a complexity
Ω
(n log n).
Algorithm
Nsort(A,n) //Sort n positive integers{ for i:= 1 to n do B[i]:=0; //Initialize B[].For i:= 1 to n
do{ j:=Choice(1,n);if B[j]
≠
0 then Failure(); // B[j] already used// B{j]:= A[i];}for i:= 1 to n-1 do // Verify order.If B[i]>B[i+1] then
Failure();write (B[1:n]);Success(); }
Algorithm 8.1: Nondeterministic sortingDefinition : Decision Problem and 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.
Any problem that involves the identification of an optimal value of a given cost function isk n o w n
as an
optimization problem.
An
optimization algorithm
i s u s e d t o s o l v e a n optimization problem.
Example 2: Maximum clique: -
A maximal complete subgraph of a graph G=(V,E) is a
clique.
The number of vertices determines the size of the clique. The max clique problemis an
optimization
problem that has to determine the size of a largest clique in G. The correspondingdecision problem
is to determine whether G has a clique of size at least k for some givenk. Let Dclique(G,k) be
a deterministic decision algorithm for the clique decision problem.If the number of vertices in G is
n, the size of a max clique in G can be found by makingseveral applications of Dclique. Dclique is
used once for each k, k=n,n-1, n-2,…, until theoutput from Dclique is 1. If the time complexity of
Dclique is f(n), then the size of a maxclique can be determined in time g(n), then the
decision problem can be solved in time g(n). Hence, the max clique problem can be solved in
polynomial time only if the cliquedecision problem can be solved in polynomial time.
Example 3:Max clique: -
The input to the max clique decision problem can be provided as a sequence of edges
and an integer k. Each edge in E(G) is a pair of numbers(i,j). The size of the inputfor each edge (i,j)
is [log
2
i]+[log
2
j]+2 if a binary representation is assumed. The input sizeof any instance isn=
∑
([log
2
i]+[log
2
j]+2) +[log
2
∈
k] + 1(i,j)
∧
1
x
2
∨
)
(x
∧
3
x
4
) and (x
∨
3
x
4
∧
)
(x
∨
1
x
2
∨
). The symbol
denotes
or
∧
and
denotes
and
. A formula is in
conjunctive normal form
∧
(CNF) if and only if it is represented as
k i=1
c
i
where c
i
∨
are clauses each representedas
l
ij
.The l
ij
are literals .It is in
disjunctive normal form
∨
( D N F ) i f a n d o n l y i f i t i s represented as
k i=1
c
i
and each clause c
i
∧
is represented as
l
ij
Thus (x
∧
1
x
2
∨
)
(x
∧
3
x
4
) is inDNF whereas (x
3
∨
x
4
∧
)
(x
∨
1
x
2
) is in CNF. The
satisfiability
problem is to determinewhether a formula is true for some assignment of truth-values to
the variables. CNF-
satisfiability
is the satisfiability problem for CNF formulas.
Algorithm DKP (p,w,n,m,r,x)
Page 164