DAA Unit5 Part-1
DAA Unit5 Part-1
DETERMINISTIC ALGORITHMS:
The algorithms, in which the result (or, outcome) of every operation is
uniquely defined, are called deterministic algorithms.
NON-DETERMINISTIC ALGORITHMS:
The algorithms, in which the outcomes of certain operations
may not be uniquely defined but are limited to the specified sets of
possibilities (i.e., possible outcomes), are said to be non-deterministic
algorithms.
The theoretical (or, hypothetical) machine executing such
operations is allowed to choose any one of these possible outcomes.
// Guessing Stage
j := Choice(l, n);
// Verification Stage
if A[j] = x then
{
write(j);
Success( );
}
write(0);
Failure( );
}
The time complexity is O(1)
PN NP
// guessing stage.
for i:=1 to n do // Choose a truth value assignment.
xi := Choice(false, true);
// verification stage.
if E(x1, x2, …, xn) = true then Success( );
else Failure( );
}
Time complexity is O(n), which is a polynomial time. So, SAT is
NP problem.
2. CLIQUE PROBLEM:
Clique problem: Clique problem takes a graph ‘G’ and an integer ‘k’
as input, and asks whether G has a clique of size at least ‘k’.
Nondeterministic Algorithm for Clique Problem:
Algorithm DCK(G, n, k)
{
//The algorithm begins by trying to form a set of k distinct
//vertices. Then it tests to see whether these vertices form a
//complete sub graph.
// guessing stage.
S := Ø; // S is an initially empty set.
for i := 1 to k do
{
t := Choice(l, n);
S := S U {t} // Add t to set S.
}
//At this point, S contains k distinct vertex indices.
//Verification stage
for all pairs (i, j) such that i ∈ S, j ∈ S, and i ≠ j do
if (i, j) is not an edge of G then Failure( );
Success( );
}