basic concepts of non deter minis tic algorithms
TRANSCRIPT
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
1/20
By: Sunil Nakum,
NITTTR,Chandigarh.
Basic Concepts of Nondeterministic
Algorithms
By: Sunil Nakum, NITTTR, Chandigarh1
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
2/20
Topics To Be Covered
By: Sunil Nakum, NITTTR, Chandigarh2
y Introduction
y Nondeterministic functions
y Searching Example
y Sorting Example
yDeterministic interpretation of nondeterministic algorithm
y Time Analysis
y Clique Decision Problem
y References
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
3/20
Deterministic Algorithm
By: Sunil Nakum, NITTTR, Chandigarh3
y Algorithms with property that result of every operation in uniquely
defined.
y They behaves predictably.
y Given a particular input, it will always produce the same output,
and the underlying machine will always pass through the same
sequence of states.
y For some problems deterministic algo. are hard to find.
y Sometimes we dont want results to be predictable.
yCertain problems cant be solved by fast deterministic algorithms.
y The above need given rise to nondeterministic algorithm.
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
4/20
Nondeterministic Algorithm
By: Sunil Nakum, NITTTR, Chandigarh4
y In theoretical framework we can remove this restriction on
outcome of every operation.
y We can allow algorithms to contain operations whose outcomes are
not uniquely defined but are limited to specified set of possibilities.
y Machine executing such operations is allowed to choose any one of
these outcomes subject to a termination condition.
y This leads to concept of nondeterministic algorithm.
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
5/20
Nondeterministic Functions
By: Sunil Nakum, NITTTR, Chandigarh5
1. Choice ( S )
y
Arbitrarily chooses one of the elements of set S.y x = choice(1,n) can result in x being assigned any of the integers in the
range [1, n], in a completely arbitrary manner.
y No rule to specify how this choice is to be made.
2. Failure()
y Signals unsuccessful completion of a computation
y Cannot be used as a return value
3. Success()
y Signals successful completion of a computation.
y Cannot be used as a return value.
y If there is a set of choices that leads to a successful completion, then onechoice from this set must be made.
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
6/20
Nondeterministic Functions (Cont.)
By: Sunil Nakum, NITTTR, Chandigarh6
y Whenever there is set of choices that leads to successful completion,
then one such set of choice is always made and algorithm terminatessuccessfully.
y Nondeterministic algorithm fails iff there exists no set of choices
leading to a successful signal.
y
Computing time of Choice, Success and Failure are taken to beO(1).
y Machines capable of executing nondeterministic algorithm is called
nondeterministic machine.
yNondeterministic machine do not exists in practice.
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
7/20
Searching Example
By: Sunil Nakum, NITTTR, Chandigarh7
1. Algorithm Search(A,n,x)
2. {
3. j:=Choice(1,n);
4. if A[j]=x then {write(j);Success();}
5. write(0);Failure();6. }
y Here number 0 can be output iff there is no j such that A[j]=x.
y Nondeterministic complexity of O(1).
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
8/20
Sorting Example
By: Sunil Nakum, NITTTR, Chandigarh8
1. Algorithm NSort(A,n)
2. {//sort n positive integers.
3. for i:=1 to n do B[i]:=0; //Initialize B[]
4. for i:=1 to n do
5. {
6. j:=Choice(1,n);
7. if B[j]0 then Failure();8. B[j]:=A[i];
9. }
10. for i:=1 to n-1 do //verify order
if B[i]>B[i+1] then Failure();
12. write(B[1:n]);
13. Success();
14. }
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
9/20
Sorting Operation
By: Sunil Nakum, NITTTR, Chandigarh9
y Auxiliary array B[1:n] is used for convenience.
y
Line 3 initializes B to 0, any value different from all A[i] will do.y for loop of line 4 to 9 each A[i] is assigned to a position in B.
y Line 6 non deterministically determines this position.
y Line 7 ascertains that B[j] has not already used.
y Order of numbers in B is some permutation of the initial order in A.
y for loop of lines 10 and 11 verifies that B is sorted in non decreasing
order.
y Its complexity is O(n).
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
10/20
Deterministic interpretation of
nondeterministic algorithm
By: Sunil Nakum, NITTTR, Chandigarh10
y Possible by allowing unbounded parallelism in computation .y Imagine making n copies of the search instance above, all running in
parallel and searching at different index values for x.
y The first copy to reach Success() terminates all other copies.
y If a copy reaches Failure(), only that copy is terminated.
y In abstract terms, nondeterministic machine has the capability to
recognize the correct solution from a set of allowable choices, without
making copies of the program.
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
11/20
How correct element is defined
By: Sunil Nakum, NITTTR, Chandigarh11
y A correct element is defined relative to a shortest sequence of choices
that leads to a successful termination.y In case if there is no sequence of choices leading to a successful
termination we assume that algorithm terminates in one unit of time
with output Unsuccessful computation.
y
Whenever successful termination is possible a nondeterministicmachine makes a sequence of choices that is a shortest sequence
leading to successful termination.
y Since machine we are defining is untrue not necessary for us to
concern ourselves with how machine can make correct choice at eachstep.
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
12/20
Decision vs Optimization
By: Sunil Nakum, NITTTR, Chandigarh12
y Any problem with answers 0 or 1 is called decision problem.
y
Algorithm for decision problem is called decision algorithm.y Any problem that involves the identification of an optimal (either
minimum or maximum) value of given cost function is known as
optimization problem. Optimization algorithm is used to solve these
kind of problems.y In NSort algo. if the number of A[i] is not distinct then many different
permutations will result in sorted sequence. We only concern with
those nondeterministic algorithms that generate unique outputs. i.e.
nondeterministic decision algorithms.y Output statement is implicit in Signals Success and Failure.
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
13/20
Time Analysis
By: Sunil Nakum, NITTTR, Chandigarh13
y
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
14/20
Binary representation of input length
By: Sunil Nakum, NITTTR, Chandigarh14
y
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
15/20
Clique
By: Sunil Nakum, NITTTR, Chandigarh15
y Clique of undirected graph G=(V,E) is vertex set C V, such that forevery two vertices in C, there exists an edge connecting the two. This is
equivalent to saying that the sub graph. induced by C is complete.
y Size of Clique is number of vertices in it.
y In some cases, the term clique may also refer to the sub graph.
yA maximal clique is a clique that cannot be extended by includingone more adjacent vertex, that is, a clique which does not exist
exclusively within the vertex set of a larger clique.
y A maximum clique is a clique of the largest possible size in a given
graph.
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
16/20
Input to Clique Decision Problem
By: Sunil Nakum, NITTTR, Chandigarh16
y
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
17/20
Clique Decision Problem Algorithm
By: Sunil Nakum, NITTTR, Chandigarh17
1. Algorithm DCK(G,n,k)
2. {
3. S:=; //S is initially an empty set.4. for i:=1 to k do
5. {
6. t:=Choice(1,n);
7. if t S then Failure();8. S:=SU{t}; //Add t to Set S
9. }
10. //At this point S contains k distinct vertex indices
11. for all pairs (i,j) such that i,j S and ij do
12. if (i,j) is not an edge of G then Failure();13. Success();
14. }
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
18/20
Clique Decision Problem
By: Sunil Nakum, NITTTR, Chandigarh18
y
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
19/20
References
By: Sunil Nakum, NITTTR, Chandigarh19
Books
y Fundamentals of Computer Algorithmd By Ellis Horowitz, SarrajSahani, Rajasekaran.
Websites
y http://www.authorstream.com/Presentation/ankush85-159135-nphard-nphard171-175-education-ppt-powerpoint/
y http://en.wikipedia.org/wiki/Deterministic_algorithm
y http://www.jiahenglu.net/course/algorithm2010/slides/np.pdf
y http://en.wikipedia.org/wiki/Nondeterministic_algorithm
y http://en.wikipedia.org/wiki/Clique_(graph_theory)
y http://www.ecst.csuchico.edu/~amk/foo/csci650/notes/ch11/NP2.html
-
8/8/2019 Basic Concepts of Non Deter Minis Tic Algorithms
20/20
Thank You
By: Sunil Nakum, NITTTR, Chandigarh20