Reg.No:
SNS College of Technology,Coimbatore-35.
(Autonomous)
B.E/B.Tech- Internal Assessment -III
Academic Year 2016-2017(Even)
Fourth Semester
Computer Science and Engineering
IT204 – Design and Analysis of Algorithms
A
(Common to CSE & IT)
Answer Key
Time: 11/2 Hours
Maximum Marks: 50
Answer All Questions
PART - A (5 x 1 = 5 Marks)
1.
Hamiltonian circuit Problem is an__________.
a) NP Complete
c) Both a and b
2. Simplex method is applicable for
a) Minimization
c) Maximization & Minimization
3. Back tracking uses_____
b) NP Hard
d) None of the above
b) Maximization
d) Not Applicable
a) DFS
b) BFS
c) Both
d) None of the above
4. Stable marriage matching problem gives preference to______ priority
a) Man
b) Woman
c) Man & Woman
d) Mathching
5. N-Queeen problem can be solved by
a) Brute Force
b) Back Tracking
c) Branch and Bound
d) Dynamic Programming
PART - B (5 x 2 = 10 Marks)
6.
Predict NP- Complete problem with example.
A problem that is NP complete can be solved in polynomial time then all NP complete problems
can also
be solved in polynomial time. Only decision problem can be NP complete.
Ex. 1) Long simple paths 2) Cryptography 3) Chess
7.
Distinguish back tracking and branch and bound.
S.No
Backtracking
Branch and bound
1
1
2.
3.
8.
State space tree is constructed using
depth first search
Finds solutions for combinatorial
Non-optimization problems.
No bounds are associated with the
nodes in the state space tree.
State space tree is constructed using
best first search
Finds solutions for combinatorial
optimization problems.
Bounds are associated with the each
and every node in the state space
tree.
Why backtracking always produces optimal solution.
Backtracking always produces optimal solution since backtracking is a systematic way to go
through all the possible configurations of a solution space for the problem instance
9.
Construct Hamiltonian cycle.
G = (V, E) be a connected graph with n vertices. A Hamiltonian cycle is a round trip path along n
edges of G which visits every vertex once and returns to its starting position. The tour of a traveling
salesperson problem is a Hamiltonian cycle.
10. Infer State Space tree.
A state space tree is a rooted tree whose nodes represent partially constructed solutions to given
problem. In backtracking the state space tree is built for finding the solution. This tree is built using
depth first search fashion
PART – C (14+14+7 = 35 Marks)
11. (a)
Explain maximum-flow problem with an example.
A flow network G=(V,E): a directed graph, where each edge (u,v)E has a
nonnegative capacity c(u,v)>=0.
If (u,v)E, we assume that c(u,v)=0.
two distinct vertices :a source s and a sink t.
G=(V,E): a flow network with capacity function c.
s-- the source and t-- the sink.
A flow in G: a real-valued function f:V*V R satisfying the following two
properties:
(or)
2
14
(b)
Define marriage matching problem. Write an algorithm to solve the 14
same. Solve the following example.
Women
Men
A marriage matchingM is a set of n (m, w) pairs whose members are selected from
disjoint n-element sets Y and X in a one-one fashion, i.e., each man m from Y is
paired with exactly one woman w from X and vice versa. (If we represent Y and X as
vertices of a complete bipartite graph with edges connecting possible. Marriage
partners, then a marriage matching is a perfect matching in such a graph.)
Stable marriage algorithm
Input: A set of n men and a set of n women along with rankings of the women
by each man and rankings of the men by each woman with no ties
allowed in the rankings
Output: A stable marriage matching
Step 0 Start with all the men and women being free.
Step 1 While there are free men, arbitrarily select one of them and do the
following:
Proposal The selected free man m proposes to w, the next
woman on his preference list (who is the highest-ranked woman
who has not rejected him before).
Response If w is free, she accepts the proposal to be matched
with m. If she is not free, she compares m with her current mate. If
she prefersm to him, she accepts m’s proposal, making her former mate free;
otherwise,
she simply rejects m’s proposal, leaving m free.
Step 2 Return the set of n matched pairs.
12. (a)
Illustrate knapsack problem and assignment problem solve it using 14
branch and bound with your own Example.
Optimization problem seeks to minimize or maximize some objective function (a tour
length, the value of items selected, the cost of an assignment, and the like), usually
subject to some constraints. Note that in the standard terminology of optimization
problems, a feasible solution is a point in the problem’s search space that satisfies all
the problem’s constraints (e.g., a Hamiltonian circuit in the traveling salesman
problem or a subset of items whose total weight does not exceed the knapsack’s
capacity in the knapsack problem),whereas an optimal solution is a feasible solution
with the best value of the objective function (e.g., the shortest Hamiltonian circuit or
the most valuable subset of items that fit the knapsack).
3
(or)
(b)
Define Sub set sum and Hamiltonian circuit. Solve it using Back 14
tracking method
Subset sum problem is to find subset of elements that are selected from a given set
whose sum adds up to a given number K. We are considering the set contains nonnegative values. It is assumed that the input set is unique (no duplicates are presented).
We are considering the set ...
Hamiltonian Circuit Problem, in an undirected graph is a path that visits each vertex
exactly once. A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian Path such
that there is an edge (in graph) from the last vertex to the first vertex of the
Hamiltonian Path. Determine whether a given graph contains Hamiltonian Cycle or
not. If it contains, then print the path. Following are the input and output of the
required function.
4
0
w/o 3
with 3
3
with 5
w/o 5
8
14
X
3
w/o 6
with 6
with 6
8
with 7
w/o 7
14+7>15
solution
13. (a)
5
w/o 6
9
X
9+7>15
15
0
with 5
with 6
w/o 5
0
w/o 6
3
11
X
X
5
X
3+7<15
11+7>14
5+7<15
X
0+13<15
8
X
8<15
Define N-Queen problem. Write procedure and solve 4-Queen 7
problem using Backtracking method.
The eight queens puzzle is the problem of placing eight chess queens on an 8×8
chessboard so that no two queens threaten each other. Thus, a solution requires that no
two queens share the same row, column, or diagonal. The eight queens puzzle is an
example of the more general n-queens problem of placing n queens on an n×n
chessboard, where solutions exist for all natural numbers n with the exception of n=2
and n=3.
(or)
(b)
Given w = {5,7,10,12,15,18,20} and m=35. Find all possible subset of
w whose sum is equivalent to m.
Subset sum problem is to find subset of elements that are selected from a given
set whose sum adds up to a given number K. We are considering the set contains nonnegative values. It is assumed that the input set is unique (no duplicates are presented).
Exhaustive Search Algorithm for Subset Sum
One way to find subsets that sum to K is to consider all possible subsets. A power set
contains all those subsets generated from a given set. The size of such a power set is
2N.
Backtracking Algorithm for Subset Sum
Using exhaustive search we consider all subsets irrespective of whether they satisfy
5
7
given constraints or not. Backtracking can be used to make a systematic consideration
of the elements to be selected.
Assume given set of 4 elements, say w[1] … w[4]. Tree diagrams can be used to
design backtracking algorithms. The following tree diagram depicts approach of
generating variable sized tuple.
**********************
Prepared by
Verified by
6
HoD/DEAN
© Copyright 2026 Paperzz