0% found this document useful (0 votes)
12 views18 pages

Ada 2016

The document is an examination paper on Algorithms Analysis and Design from May 2016, covering topics such as Binary Search, Quicksort, NP-Complete problems, and the Branch and Bound technique. It includes questions and answers related to algorithm complexities, properties of NP-Complete problems, and various sorting algorithms like Merge Sort and Strassen's algorithm. The paper emphasizes understanding algorithm efficiency, design strategies, and optimization techniques.

Uploaded by

rajshekhar912879
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views18 pages

Ada 2016

The document is an examination paper on Algorithms Analysis and Design from May 2016, covering topics such as Binary Search, Quicksort, NP-Complete problems, and the Branch and Bound technique. It includes questions and answers related to algorithm complexities, properties of NP-Complete problems, and various sorting algorithms like Merge Sort and Strassen's algorithm. The paper emphasizes understanding algorithm efficiency, design strategies, and optimization techniques.

Uploaded by

rajshekhar912879
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ALGORITHMS

ANALYSIS & DESIGN OF

May 2016
Paper Code: CSE-306-F

each section. Q. No. 1 is


in all, selecting one question from
Note: Anempt five questions
compulsorn: answer.
function grows faster e" or 2" ? Justify your
Q.1.(a) Which
Ans. e" will grow
faster.
Reason e=2.718
as we know, (2.718"> 2"
various cases of Binary Search complexity.
Q.1.(b) Analyze the
Search
Ans. Analysis of Binary
Best case- 0 () comparisons is the middle in the array A.
In the best case, the item X
required.
of comparisons (actuallyjust 1)
are
[Link] number
Worst case -O (log n) comparisons
not exist in the array A at all.
In the worst case, the item X does
the size of the admissible
each recursion or iteration of Binary Search,
Through
n ) times. Thus, ceiling(lg n) comparisons
are
is halved. This halving can be done ceiling(lg
range
required.
Average case O (log n) comparisons of number of
over all elements of the product
To find the average case, take the sum
for that element.
to find each element and the probability of searching
comparisons required and
item which is not in A will be seàrched for,
To simplify the analysis, assume that no
element are uniform.
that the probabilities of searching for each
of quick sort.
Q.1.(c) Using big-O notation state time and space complexity
Ans. Quicksort Time complexity:
Worst Case = O(n)

Average Case
=
O(n*log(n)
Best Case = O(n*log(n))
code is optimized
Quicksort Space Complexity: The space complexity O(n) ifthe
is but
be reduced to O{log(n))
ifcode uses iterative bottom up space complexity can
approach)
Q.1.d) What is the difference between greedy and dynamic approach ?
Ans. Differences are:
Greedy approaches Dynamic approaches
[Link] efficient 1. Less efticient
[Link] solution cannot be guaranteed [Link] solution can be guaranteed.
by a greedy algorithm.
3. No efficient solution. 3. DP provides efticient solutions for
some problems for which brute force
a

approach would be very slow.


48 Analysis and Design of Algorithm

recurrence.

e master method beapplied o solve

T)-47 logn ? why or why not ?


Ans. T(n)47 logn
t has the proper n* logn
torm:a= 4, h- 2.f(m)
n log2
It might seem that case 3 should apply, since f(n) = n* log n is asymptotically larger
log
=?. The problem is that it is not polynomially larger. The ratio
f(nyn6"nlogn
- log n is asymptotically less thanb for carry any positive constant e.
The recurrence falls into the gap between case 2 and 3 case. So we can not determine. Hence
the master method can not apply.
Q.1.00 What are three properties of NP-Complete problem ?
Ans. Properties ofNP -complete Problems
(i) No polynomial time algorithm has been found for any NP-Complete problem.
(i) lt has not been established that polynomial time algorithms for these problems are
not in existence.
(ii) If a polynomial time algorithm is found for any NP complete problems, then there
will be polynomial time algorithms for all such problems
(iv) It be proved that if no polynomial time algorithm exists for
can
any such problem,
then definitely for any other such problem, it will not exist.

Q.1.(8) Explain Branch and Bound technique.


Ans. Branch and bound is a systematic method for solving
optimization problems. B&B
is rather general optimization technique that applies where the greedy method and
a
dynamic
programming fail. However, it is much slower. Indeed, it often leads to exponential time
complexities in the worst case. On the other hand, if applied carefully, it can lead to algorithms
that run reasonably fast on average.
B&B Technique -

I. The first idea of B&B is to develop "a predictor" ofthe likelihood (in a loose sense)of
a node in the solution tree that it will lead to an optimal solution. This predictor is quantitative.
2. Which node to expand next: B&B chooses the live node with the best predictor value
3.B&B simply expands that node (i.e., generate all its children)
The node is computed, just expanded node is
4. predictor value of cach newly generated
now designated as a dead node, and the newly generated nodes are designated as live nodes
[Link] criterion : When the best node chosen for expansiom turn out to be a final
leaf(i.e, at level n), that when the algorithm terminates, and that node corresponds to the optimal
solution.
49
2016
BTech, 6 Semester Solved papers, Ma
with examnples.
Hamiltonian cycles or Hamilton
Q.1.(h) Discuss
Hamiltonian circuit, Hamilton cycle,
Hamiltonian cycle, also
called a
that visits each node exactly
once.
Ans. A
closed loop) through graph
a
circuit, is graph cycle (i.e.,
a

Examples: vertices is Hamiltonian


with more than two
() a complete graph
is Hamiltonian
(1) every cycle graph Hamiltonian paths
has an odd number of
(iii) every tournament Hamiltonian
considered as a graph, is
(iv) every platonic solid,
Hamiltonian
(v) every prism is non-hamiltonian
Archimedean dual
the
Deltoidalhexecontahedron is only
(vi) The
Hamiltonian
(vii) Every anti-prism is Hamiltonian.
no with separating triangles is
(vii) A maximal planar graph
Section A

matrix multiplication
with example.
Q.2.(a) Explain strassen's Volker Strassen, is an algorithm
used for matrix
named after
Ans. The Strassen algorithm,
than the standard matrix multiplication
algorithm and is useful in practice
multiplication. It is faster for extremely lar
but would be slower than the fastest known algorithm
for large matrices,
matrices.
matrices A and B.
Given: Two N by N
Problem: Compute C =A x B
Brute Force
for i:-I to N do

forj:=l to N do
C[ij):=0;
fork=1 to N do
Cfij-C[ij] +A[ik]* B[kj]
ON) multiplications
Divide and Conquer
B
C2 B B2
PP. = (4,,
= t
A,,)XB,t B,)
(A., + A,,)XB,,)
P, = (4,,)B, - B,)

P, = (4,)XB,- B,)
P. = (4,, t AMB,.)

P (4, 4,XB,,+ B,,)


P, (4-A,XB.,+ B,)

C(P, P,)
C(P,P )
C (P+P- P. + P)
50 1nalysis und
Design of Algoriu
From
7T(n/2)+ Cn ifn>1|
T(n) =
C ifn=1)
Tn)- Oury') = O(n").

Q.2.(b) Write algorithms for Union& Find operations for disjoint sets.
Ans. A union-find algorithm is an algorithm that performs two useful operations on suet
a data structure:
Find: Determine which subset aparticular element is in. This can be used for detemining
if two elements are in the same subset.
Union: Join two subsets into a single subset.
procedure Make-Set (x)
[Link][x] 1
2. parent[x X

end.
procedure UNION(a, b) {with weightbalancing
a and b are roots of two distinct trees in the forest.}
{Makes the root of the smaller tree a child of the root of the larger tree.}
1. if sizefa] < size[b] then a b
2. parent[b] a
3. sizefa sizela] +size[b]
end.
function FIND(x) {with path compression}
{Returns the root ofthe tree that contains node x.}
1. if parent[x] =* x then
2. parent[x] FIND(Parent[ )
3. return parent|x
end.

Q.3.(a) What is Merge Sort ? Write a recursive algorithm for same and show
that its running time is Ofn log n).
Ans. Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves.
calts itself for the two halves and then merges the two sorted halves. The merg() function is used
for merging two halves. The merge(arr, 1, m, r) is key process that assumes that arr[l.m] and
sorted and merges the two sorted sub-arrays into one. See following C
arr(m+1..r] are
implementation for details.
Algorithm: Merge sort (4, P, q, r)
()n4-ptl
(2) n r - 4
51

May 2016
[Link],
Semester Sohed pupers,
Array L{1,
2 .

1 . . .

n1 +
Create
(3) R{1,2.. 2 +1
(4) f o r i | to n.+
i-)
(5) do L[i]-A[P
t0 n2
(6) for+
(7) do
R[ A (q+)

(8) L[n+1]
(9) R[n2+1]o
(10) i
(1) - 1
(12) k - p to r

(13) do
ifLI> R[l
(14) then A[k] - L[J
(15) i - i + 1

(16) else
A [K]- R[Ll
(17)j-j+1 each divide step
that 'n' at a power of 2 i.e.
Analyzing Merge
sort : We assume

decide the Merge sort (4, p, r)


Pr
0 (1)
If
then 0 (1)
p+r)2
Merge sort (4, p, r). »0(n/2)
0 (n/2)
Merge sort (4,q+1,r)
>0 (n)
Merge sort (4,p. 4, r)
Problem into two subProblem
of size exactly n/2.
When n
=
| Base case occurs
time.
When n2 2 we break down running
time as
The recurrence for merge sort running

e(1) ifn=1

Toa0 ifn>l

We can write as

C ifn=1

+Cn ifn>l
Analysts and Design of Alg
ntm
52
Recursion Tree
Cn

TC, log (m) + 1]


= Cn logn+Cn
= n log n

sort algorithm
Q.3.(b) What is Divide and Conquer strategy? Explain Merge
with example. Also give its recurrence relation.
Ans. Divide and Conquer strategy : Divide and conquer is a technique for designing
of smaller
algorithms that consists of decomposing the instance to be solved into number
a
subinstance of the same problem, solving successively and independently each of these

subinstances, and then combining the subsolutions thus obtained to obtain the solution of the

original instance.
Most ofthe algorithms are recursive in natare. To solve a given problem they call them
selves recursively one or more times. All these algorithms follows "Divide and conquer" approach
The Divide and conquer paradigm involves three steps at each level ofrecursion
(1) Divide: In this step whole problem is divided into number of several subproblems.
(2) Conquer: The subproblems by solving them recursively. Ifthe subproblem size are.
small enough, however, just solv the subproblem in a straight forward manner.
(3) Combine: Finally, the solutions obtained by the subproblems are combined to create
solution to the original problem.

Algorithm:
Input: An array a and two indices p and q between which we want to do the sorting
Output: The array a will be sorted between p and q as a side effect
ifpq then
int m -pq/2
mergeSort(a.p.m)
mergeSort(a,m* 1.9)
merge(a.p.m.q)
The pseudo code of the merging routine is as follows:
Algorithm merge(a,p,m,q)
Input: An array a, in which we assume that the halves from p:::m and m-[Link]q are eacn
Sorted
2016
0* Semester Solvedpaers. Mar
B Tech. and q
sorted between p
The array should be result
Output: will hold the temporary
pt| // this array
Array tmp ofsize q
inti-p
int-j mt
int k -
do
while (i<= m orj<=q)
<=a.i) then
ifg q+l or alil
tmp[k]-a[i
ii+l
else if(i =
m+1 or afi]> a[j}) then
tmp[kl-a[)
J
k-k+1

fork=pto q do
a[k]-tmp[k]
the data is partitioned into two, one list of 6.
call of the function,
Example: For the first two smaller
7 and 2. The list (6 58 1) is then partitioned into
5,8 and 1, and a second list of 4, 3,
we can sort ( 6 5) into
and ( 8 1). The base case has now been reached, and
lists (6 )5
We compare
8 We can now merge (S 6 ) and (I 8).
(56) and we can sort ( 8 1) into (1 ). second
is 1. We next compare 5 and 8, so the
and 5, so the first element ofthe merged sequence
element will be 6, leaving 8 as the last element.
element is 5. Next we compare 6 and 8 the third
to the second halfofthe original data
The merged result is(1568). We now turn our attention
7 these we get ( 3 4) and
[Link] we partition ( 4 3 72 ).into ( 4 3) and ( 2).Sorting
two halves of the data sorted as
(2 7) Merging these we get ( 2347). We now have
(1568) and (2 3 4 7).All that remains to be done is to mergethe two halves together.

(12345 678)
Recurrence relation: T(n)=2T(n/2) + C,

Section B

Q.4.(a) Use Dijkstra algorithm to find single source shortest path for following
graph taking vertex *A' as the source.

10 B

D E
Analys1s and
Design of Al
Ans.
2
4

D
3
E
C D E
A B

0
2

Node A is selected

AB C D E

10 7

Now, select next node with min. value. i.e. next selected node is D

2
10
10

3
Relaxing edges from node D.

10

10
8Tevk, Semester. Sohed papers, May 2016 55

A B C D

10 12 10

Next selected node is E


2
10 12

10

Next selected node is C

2
10 12

O
10
A 10
C

12
D E

Next selected [Link] B

2
10
10 12
/3

(7 3

Next selected node is 12

A B C D E

D 12
56 Analysis und Destgiu of Algurithms

2
12
10
(10
(o
7

for finding minimum spanning tree of an


Q.4.(b) Write Kruskal's algorithm
undirected graph.
Ans. Kruskal's algorithm is a greedy algorithm in graph theory that finds a minimum
tree for a connected weighted graph. It finds a subset of the edges that forms a
tree
spanning
that includes every vertex, where the total weight of all the edges in the tree is minimized.
This algorithm is directly based on the MST( minimum spanning tree) property.

MST-KRUSKAL(G w)
1. A?
2. for each vertex v V[G]
3.
3. do MAKE-SET(V)
4. sort the edges of E into nondecreasing order by weight w
5. for each edge (u, v) E, taken in nondecreasing order by weight
6. do if FIND-SET(u) ? FIND-SET(v)
7. then A?A {(u, v)}
8. UNION (u, v)
9. return A

Q.5.(a) Explain Traveling Salesman Problem.


Ans. Traveling Salesman Problem (TSP) : Given a set of cities and distance between
every pair ofcities, the problem is to find the shortest possible route that visits every city exactly
once and returns to the starting point.
Note the difference between Hamiltonian Cycleand TSP. The Hamiltonian cycle problem
is to find ifthere exist a tour that visits every city exactly once. Here we know that Hamiltonian
Tour exists (because the graph is complete) and in fact many such tours exist, the problem is to
find a minimum weight Hamiltonian Cycle.
This is one of the most known problems ,and is often called as a difficult [Link]'s
[Link] let's assume
number the cities from I to n ,and let city 1 be the city-base of the
that c(ij) is the visiting cost from i to [Link] can be c(ij)>cj,i).Apparently all the possible
for
solutions are (n-1)!.Someone could probably determine them [Link] the cost
each and everyone of these solutions and finally keep the one with the minimum [Link]
requires at least (n-1)! steps.
(n-1)!=(21-1)!=20! [Link]
Iffor example there were 21 cities the steps required are

every step requireda msec we would need about 770 centuries of [Link],the
exhausting examination of all possible solutions is out ofthe [Link] we are not aware o
any other quick algorithm that finds a best solution we will use a heuristic algorithm. According
BTech, Semester Solvedpapers, lay 2016 57
to this algorithm whenever the salesman is in town he chooses as his next city, the city j for
which the c(i.j) cost,is the minimum among all c(i.k) costs, where k are the
salesman has not visited [Link] is also a simple rule
pointers ofthe city the
in
just case more than one cities give the
minimum cost,for example in such a case the city with the smaller k will be
[Link] is a
greedy algorithm which selects in every step the cheapest visit and does not care whether this
will lead to a wrong result or not.

Input Number of cities n and array of costs c(ij) ij=1,..n (We begin from
number 1) city
Output:Vector of cities and total cost.

starting values ")


C-0
cost=0
visits-0
e1 (°e=pointer of the visited city)
( determination of round and cost)
for - to n-1 do
choose of pointer j with

minimum=c(ej)Fmin{c(e,k)};visits(k)=0
cost cost+minimum
andk=I,..n}
ej
Cr)=j
end r-loopp
C(n)=1
cost=cost+c(e,1)
Q.5.(6) Set n =
7; (pl, p2 ..p7) (3,
5, 20, 18, 1, 6, 30) and
=

(d1, d2,..., d7) (1, 3, 4, 3, 2, 1, 2).


=

What is the
solution generated by job
Ans. n7 sequencing algorithm for given problem?
3
5
d
20
d-
18
da
d
6
P 30 d-1
Sort the task in
descending order of protit.
4 6
P 30 20
d 18 6 3
20 4 3 3 2
and
58 Analysis esign of lgorithms
Size of array is 7
initialized array with 0
3 4 56 7

Assign task 7to slot2


23 4 56 7
Profit 30

Assign task 3 to slot 4


I2 3 4 5 6 7
Profit 50
o 30 0 20 0 0 0
Assign task 4 to slot 3
2 3 4 5 6
7 Profit 68
o 30 18 20 0
Assign task 2 to slot 3 but reject task 2
3 5 6 7
12 4
Profit 74
30 1820 000
Task I is also rejected
3 4 56 7
Profit 74
6 30 18|20
Task 5 is also rejected
2 3 4 5 67
Profit 74
630 18 | 2000o
Optimal task sequence is
P P , with Max. Profit 74
P B
Section C
Q.6.(a) Discuss how 8-Queen's Problem is solved through Backtracking.
Ans. Algorithmn:
- Start with one queen at the first column first row
Continue with second queen from the second column first row

- Go up until find a permissible situation


- Continue with next queen
We place the first queen on AI. Note the positions which QI is attacking. So the next
Q2 has to options: B3 or B4. We choose the first one B3. We backtrack to Q3 and try
to
queen
find admissible place different from [Link] we need to backtrack. Q2 has no other choice
and finally we reach QI. We place Ql on A3.
intPlaceQueen(int board[8], int row)
B. Tech., 6th Semester.
Solved papers. May 2016 59
If (Can place queen ith
on column)
PlaceQueen(newboard, 0)
Else

PlaceQueen(oldboard,oldplace+1)
End

Q.6.(b) Explain LC Branch-&-Bound with


example.
Ans. When a node is visited the first time called
an E-node, all its children are
and saved into a data structure called live-node. If the child is generated
not bounded; the structure could
be a LC, or Least Cost. Exactly one node is
pulled out the live-node list at a time, which becomes
an E-node, to be
"expanded" next. The LC (least-cost) branch-and-bound strategy uses heuristics
to determine the best node for
expansion from the current live nodes.
Example: The 15-puzzle
-

15 numbered tiles on a square frame with a capacity for 16 tiles.


Given an initial arrangement, transform it to the goal arrangement through a series of
legal moves.
-

Legal move involves moving a tile adjacent to the empty spot E to E.


- Four possible moves in the initial state above: tiles 2,3, 5,6.
Each move creates a new arrangement of tiles, called state of the
-

puzzle.
Initial and goal states.
-

A state is reachable from the initial state if there is a


sequence of legal moves from
-

initial state to this state.


state space of an initial state is all the states that can be reached from initial state.
The
-

Search the state space for the goal state and use the path from initial state to goal state
as the answer.
Number of possible arrangements for tiles: 16! H" 20.9x 1012.
-

-Check whetherthe goal state is Yeachable from initial state.


Number the frame positions from 1 to 16pi is the frame position containing tile numbered
i. pl6 is the position ofempty spot. For any state, let li be the number oftiles j such that j <i and
pi> pi. Forthe initial arrangement above, I1 = 0, 14 = 1, and 112 6 .

Let x=1 ifin the initial state, the empty spot is in one of fhe following positions: 2, 4. 5.
7, 10, 12, 13, 15; otherwise x = 0.

Q.7.(a) Write Backtracking


algorithm to find chromatic number of a given graph.
Ans. Chromatic number of a graph "G' is the smallest number of color needed to color
the vertices of G So, that no two adjacent vertices share the same color.
The chromatic number of a graph 'G' is denoted by r(G).
Algorithm:
Algorithm m coloring
(int k)

do

x[k] = get node color ( k ) ;


i f( r [k]= = 0) return;
60 Analysis and Design of Algorth
ithm
if (k ==n)
write (r [l . . n]) :
else
m
coloring (k + 1):
while (true)
int getnode color (int k) {
ll x [I]. x [2].. [k- I]
[k] |0..... mj
do {
r [k] = (* [k] +1) mode (m + 1)

if(r [k] =0)


return;
for(j =1:j< =n;+ +){
if(G [] [j]#0 & & r[k] = = x [ / )

break
i f (j = n+ 1)

return;
while (true)

Q.7.(b) What O/1 knapsack problem ? Slove this problem using Branch & Bound
method taking suitable example.
Ans. O-1 Knapsack problem: If a thief carries all or none of a good in the store
which cannot be parted or broken then it is called O-1 Knapsack problem.
Branch & Bound is very powerful tool to solve optimal problem when you haveto
maximise something when given some constraints.
Branch & Bound Problems solve 0/1 knapsack problem Statement:
Given 'n' items withbenefits b.b..b& weights ". W ", & max. capacity of
knapsack M. Find the items that should be chosen that maximize benefit.
0 not choose the items
choose theitems.
Process: Let us have X1, X2 . .

x, e {0, 1}
We need to maximize

Constraint 2 xism
i=l i=
(Maximize)
as we have to make "n' choices
2" possibilities are there
[Link]., 6h Semester: Solved papers. May 2016 61

O|1 0|1 ...... O|1


2 x 2 x. ...x 2=2"

0/1 knapsack Problem : Example using nm= 12 Branch & Bound

Items () Weigth(w) Value (v))


W
50 10
8 48 6
6 30 5
4 16 4

ub v+ (w w) (V; +
1" + 1
= -

Arrange the table according to its descending values of per weight Ratio.
Now start with root node, th upper bound for the root can be computed as
ub = 0 + ( 1 2 - 0 ) * 10= 120

V = 0, 1r = 0, v,h = 10

w 0,v =0|
ub 12
Include I, Exclude I,
w = 5 , v = 50|
w=0,v=0
ub 92 ub 72
Include l. Exclude X
ww 13 w=5. v= 50|
2th 85
Not feasible l
Include 1 Exclude
X
W=11, v= 80 wW=5.v =50|
ub 84 ub= 78 X
Include I Exclude
w 15 w=11, v = 80|
Not feasible 1b-80
Optimal solution
X
Section D
Q.8.(a) Giving suitable example prove that traveling Salesperson Problem is
NP-complete.
Ans. TSP is NP-complete: Instance: Aúnite set of cities tc,: c.: c . ) , a positive
integer distance di. j) between each pair (e, c), and an integer B.
Aulysas Und 1estgn of Algorithme
62

ot h e CIles Is a certilicate th
Cng salesman is NP complete since a permutation a reduction
that traveling salesman is NP-complete
we descriC from
e [Link] prove
hamiltonian cycle.
OVen an instance of hamiltonian cycle g (with n vertices), create an instance of traveling

salesman.
-
For each vertex v, create a city cv:
-It there is an edge (7,v), then let the distance from cu to cv be l
-

Otherwise let the distance be 2.


Claim: G has a Hamiltonian Cycle if and only if there is a route of distance at most n.
Proof: If G contains a cycle, then the cycle forms a route through the cities of distance
n. If there is a route of distance n through the n cities,then clearly the distance between each
is adjacent in G and the
pair of cities along the route is 1. Thus each pair ofcities along the route
route is a hamiltonian cycle.

Q.8.(b)Show that Clique decision problem is NP-hard.


Ans. Given a graph G, find the largest clique (set of nodes such that all pairs in the set
are neighbours).
Decision problem: "Given G and integer k, does G contain a clique of size > k?
Proof: We will reduce 3-SAT to Max-Clique. Speciûcally, given a 3-CNF formula F of
m clauses over n variables, we construct a graph as follows. First, for each clause c of F we
create one node for every assignment to variables in c that satisûes c. E.g., say we have:
F r , v X, v X) a ( v x,) n (r, v x)A
Then in this case we would create nodes like this:
(x =

(x, =
0, x =0, x, 0) (r, 0, x,
= =

0, x, = 1 ,x , = 0) (r, = 0, *, =
=
0) (r, =
0, x,
) ( r , = 0, x, = 1)
=
0)...
(a, = 0 , , = 1, x ) , 1 , x , = ) « , = 1 ,x , = 0)

( 1, , 0, x, 0)
= =

(r, 1, x, 0, ,= I)
=

(r, 1, 1,x, 0)
r 1, x, 1, x, 1)
= = =

We then put an edge between two nodes ifthe partial assignments are consistent. Notice
is between any two nodes
because there edges
that the maximum possible clique size m are no

c. Moreover, if the 3-SAT problem does have a satisfying


that correspond to the same clause
assignment, then in fact there iIS an m-clique gust pick some satistying assignment and take the
k= m) is correct
m nodes consistent with that assignment). So, to prove that this reduction (with
we need to show that if there
isn't a satisfying assignment to F then the maximum elique in the
graph has size < m. We can argue this by looking at the contrapositive. Speciücally, if the graph
has an m-clique, then this clique must contain one node per clause c. So. just readoffthe assignment
given in the nodes of the clique: this by construction will satisfy all the clauses. So, we have
shown this graph has a clique of size m iff F was satisfiable. Also, our reduction is polynomial
time since the graph produced has total size at most quadratic in the size of the formula F(O{m)
nodes,O(m) edges). Therefore Clique is NP-complete.
8 Teh. Semester. Sohed pupers. \ar 2016 63

Q.9. Write short notes on


(a) Difference between deterministic and non deterministic algorithms.
(b) NP-hard and NP complete problems
(c) Cook's theorem.
Ans.(a) Difference between deterministic and non deterministic algorithms
A deternministic algorithm is an algorithm which. given a particular input. will always produce
the same output. with the underly ing machine always passing through the same sequence of
states. ENamples: Skewed matrix products
Von-deterministic algorithm is an algorithm that can exhibit different behaviours on
ditferent runs, as opposed to a deterministic algorithm. There are several ways an algorithm mnay
behave differently from run to run. A concurrent algorithm can perform differently on different
uns due to a race condition. A probabilistic algorithm's behaviour depends on a random number
generator. An algorithm that solves a problem in non-deterministic polynomial time can run in
polynomial time or exponential time depending on the choices it makes during execution.
Example : Merge sort
split the collection in two approximately equal parts
sort the two halves with merge sort (i.e. recursively)
merge the results
Items can only be uniquely sorted if the sorting criterion chosen always defines a total
order; e.g. student numbers are expected to be unique, but if we sort exams by name and two
students happen to have the same name, the order in which their exams get sorted is left undefined.
In such cases, merge sort will always arrive at one ofthe possible valid orderings, but which one
is left unspecified - hence it is nondeterministic.

Ans. (b)NP-hard: NP-hard (non-deterministic polynomial-time hard), in computational


complexity theory, is a class of problems that are, informally, "at least as hard as the hardest
problems in NP". A problem H is NP-hard ifand only if there is an NP-complete problem L that
is polynomial time Turing-reducible to H. L can be solved in polynomial timne by an oracle
machine with an oracle for H. Informally, we can think of an algorithm that can call such an
oracle machine as a subroutine for solving H, and solves L in polynomial time,ifthe subroutine
call takes only one step to compute. NP-hard problems may be of any type: decision
problems, search problems, or optimization problems.
NP-hard problem are at least as hard as NP-Complete problem. Hence there are no
poly nomial problem algorithms defined.
Example of NP-hard problem is
(a) Considerthe halting problem for determining algorithms.
(b) is well known that the halting problem is undecidable. Hence there exists no
algorithm to solve the problem. Therefore it clearly cannot be NP:
NP-Complete: Thecomplexity class NP-complete is a class of decision problems. A
decision problem L is NP-complete if it is in the set of NP problems and also in the set of NP-
hard problems. The abbreviation NP refers to "nondeterministic polynomial time."
Analyss amd Desigr of igorithms
64
in
NP-complete
A decision problem D is said to be
-

It belongs to elass NP.


reducibleeto
to D.
problem in NP is polynomially
Every
Np-Complete

NP
Np-Har

NP-Hard and NP-complete. A


From abovediagram, there are two classes of problems
problem is NP-complete has the property that it can be solved in polynomial time if and only ifall
over NP-complete problems can be solved in the polynomial
time.
Example of NP-Complete problem:
Let us prove that the Hamiltonian circuit problem is polynomially reducible to the
decision version ofthe traveling salesman problem.
- It can be stated as the problem to determine whether there exists a Hamiltonian cireuit
in a complete graph with positive integer weights whose length is not greater than given positive
integer m.
- We can map a graph G of a given instance of the Hamiltonian circuit problem to a
complete weighted graph G representing an instance ofthe traveling salesman problem by assiyning
I as weight to each edge in G and adding edge of weight 2 berween any pair of not adjacent
vertices in G.
- As the upper bound m on the Hamiltonian circuit length, we can take m=n. where m
is the number of vertices in G and G'. Therefore this transformation can be done in polynomial
time. So problem is NP-complete.
The decision version of problems are NP-complete whereas the P optimization versions
of such difficult problems fall in the class of NP-Hard Problems.

Ans.(c) Cook's theorem: Refer Q.8(6) of paper May 2014.

You might also like