Documente Academic
Documente Profesional
Documente Cultură
SEMESTER IV
CS 2251 DESIGN AND ANALYSIS OF ALGORITHMS 3104
UNIT I 9
Algorithm Analysis – Time Space Tradeoff – Asymptotic Notations – Conditional
asymptotic notation – Removing condition from the conditional asymptotic notation -
Properties of big-Oh notation – Recurrence equations – Solving recurrence equations –
Analysis of linear search.
UNIT II 9
Divide and Conquer: General Method – Binary Search – Finding Maximum and
Minimum – Merge Sort – Greedy Algorithms: General Method – Container Loading –
Knapsack Problem.
UNIT III 9
Dynamic Programming: General Method – Multistage Graphs – All-Pair shortest paths –
Optimal binary search trees – 0/1 Knapsack – Travelling salesperson problem .
UNIT IV 9
Backtracking: General Method – 8 Queens problem – sum of subsets – graph coloring –
Hamiltonian problem – knapsack problem.
UNIT V 9
Graph Traversals – Connected Components – Spanning Trees – Biconnected components
– Branch and Bound: General Methods (FIFO & LC) – 0/1 Knapsack problem –
Introduction to NP-Hard and NP-Completeness.
TUTORIAL = 15 Total = 60
TEXT BOOK:
1. Ellis Horowitz, Sartaj Sahni and Sanguthevar Rajasekaran, Computer Algorithms/
C++, Second Edition, Universities Press, 2007. (For Units II to V)
2. K.S. Easwarakumar, Object Oriented Data Structures using C++, Vikas
Publishing House pvt. Ltd., 2000 (For Unit I)
REFERENCES:
1. T. H. Cormen, C. E. Leiserson, R.L.Rivest, and C. Stein, "Introduction to
Algorithms", Second Edition, Prentice Hall of India Pvt. Ltd, 2003.
2. Alfred V. Aho, John E. Hopcroft and Jeffrey D. Ullman, "The Design and Analysis of
Computer Algorithms", Pearson Education, 1999.
UNIT-I
PART – A
3. Define Algorithm & what are the steps to write an Algorithm (or) Explain
algorithm specification?
Ans:
Algorithm:
The collection of unambiguous instructions occurring in some specific sequence.
Steps to write an Algorithm:
• pseudo code conventions
Alg is the procedure consisting of heading and body.Heading consists of the
keyword Algorithm,name of the Alg and parameter List.
Syntax:
Algorithm name (p1,p2…………………..pn)
PART – B
1. Write the algorithm for finding the maximum and minimum and explain it?
Ans: The problem is to find the maximum and minimum items in a set of n
elements.Though this problem may look so simple as to be converted it allows us to
demonstrate divide and conquer in simple setting.
Iterative algorithm
Algorithm straightmaxmin(a,n,max,min)
{
max:=min:=a[1];
for I:= 2 to n do
{
if(a[I]>max) then max:=a[I];
if(a[I]<min) then min := a[I];
}
}
Recursive algorithm
Algorithm maxmin(I,j,max,min)
{
if(I==j) then max:=min:=a[I];
else if (I=j-1) then
{
if(a[I]<a[j]) then
{
max:=a[j];
min:=a[I];
}
else
{
max:=a[I];
min:=a[j];
}}
else
{
mid:=(I+j)/2;
maxmin(I,mid,max,min);
maxmin(mid+1,j,max1,min1);
if ( max< max1) then max:= max1;
if(min > min1) then min:= min1;
}}
UNIT – III
PART - A
1. What is the Quick sort?
Ans: n quicksort, the division into subarrays is made so that the sorted subarrays
do not need to be merged later.
2. Write the Anlysis for the Quick sort.
Ans: In analyzing QUICKSORT, we can only make the number of element
comparisions c(n). It is easy to see that the frequency count of other operations is of the
same order as C(n).
3. Is insertion sort better than the merge sort?
Ans:Insertion sort works exceedingly fast on arrays of less then 16 elements,
though for large ‘n’ its computing time is O(n2).
4. Write a algorithm for straightforward maximum and minimum
Ans: algorithm straight MaxMin(a,n,max,min)
//set max to the maximum and min to the minimum of a[1:n]
{
max := min: = a[i];
for i = 2 to n do
{
if(a[i] >max) then max: = a[i];
if(a[i] >min) then min: = a[i];
}
}
1. Devising algorithms for finding exact solutions (they will work reasonably fast only
for relatively small problem sizes).
2. Devising "suboptimal" or heuristic algorithms, i.e., algorithms that deliver either
seemingly or probably good solutions, but which could not be proved to be optimal.
3. Finding special cases for the problem ("sub problems") for which either better or
exact heuristics are possible.
As a graph problem
Computing a solution
Using inversion instead, the salesman starts with the shuffled cards laid out in front of
him. First, he calculates the path length. Then he randomly picks four contiguous cards
and inverts their order (i.e. A B C D -> D C B A). After recalculating the path length, he
keeps the new order if it is shorter as in the figure below with 6 towns (note: the
hometown, point 1, is not counted).
For 60 towns, a loop is randomly opened more than once in every 602 attempts. If the
salesman has a friend with an identical card deck, then they can double their chances of
opening a loop. They both lay out the cards in the same order, then randomly select
different sets of four cards to invert. Naturally, more friends working in parallel will
continue to improve the odds. The figure below shows a randomly generated path
connecting 60 points.Each iteration has 180 parallel inversion operations (i.e. friends), 60
of which are combined to make a new path. After about 1500 iterations, all loops have
been opened, reducing the tour to 1/5 of the original length. See figure below.
UNIT - IV
PART - A
PART – B
Example:-
The problem is to place eight queens on a 8 x 8 chessboard so that no two queen “attack”
that is, so that no two of them are on the same row, column or on the diagonal.
4. Explain Hamiltonian circuit problem.
A Hamiltonian path or traceable path is a path that visits each vertex exactly once. A
graph that contains a Hamiltonian path is called a traceable graph. A graph is
Hamilton-connected if for every pair of vertices there is a Hamiltonian path between the
two vertices.A Hamiltonian cycle, Hamiltonian circuit, vertex tour or graph cycle is a
cycle that visits each vertex exactly once (except the vertex which is both the start and
end, and so is visited twice). A graph that contains a Hamiltonian cycle is called a
Hamiltonian graph.Similar notions may be defined for directed graphs, where each
edge (arc) of a path or cycle can only be traced in a single direction (i.e., the vertices are
connected with arrows and the edges traced "tail-to-head").A Hamiltonian
decomposition is an edge decomposition of a graph into Hamiltonian circuits.
Any Hamiltonian cycle can be converted to a Hamiltonian path by removing one of its
edges, but a Hamiltonian path can be extended to Hamiltonian cycle only if its endpoints
are adjacent.The line graph of a Hamiltonian graph is Eulerian. The line graph of an
Eulerian graph is Hamiltonian.A tournament (with more than 2 vertices) is Hamiltonian if
and only if it is strongly connected.A Hamiltonian cycle may be used as the basis of a
zero-knowledge proof.
Number of different Hamiltonian cycles for a complete graph = (n-1)! / 2.
Number of different Hamiltonian cycles for a complete Digraph = (n-1)!.
5. Explain generally about Backtracking.
Backtracking is used to solve problems with tree structures. Even problems seemingly
remote to trees such as a walking a maze are actually trees when the decision 'back-
left-straight-right' is considered a node in a tree.
Aims
Backtracking is the approach to find a path in a tree. There are serveral
different aims to be achieved :
• just a path
• all paths
• the shortest path
depending on the algorithm and the problem, 'just a path' is the first solution. The
shortest path can only be determined when all paths are known, hence the order of the
listing.
Implementation considerations
The implementation bases on recursion. Each step has to be reverseable,
hence the state has to be saved somehow. There are two approaches to save
the state :
• as full state on the stack
• as reversable action on the stack
While the former is simpler it uses more stack. The later may be preferred for bigger
problems. Consider a game with 100x100 places. To mark the visited places as array
takes 10k booleans per step. The most unfortunate solution, where all places have to be
visited has 10k steps with 10k booleans each as state, therefore using 100M booleans on
the stack with the first approach. The later uses several orders of magnitude less stack
when just saving the position
Implementation
As usual in a recursion, the recursive function has to contain all the knowledge.
The standard implementaion is :
1. check if the goal is achieved
REPEAT
2. check if the next step is possible at all
3. check if the next step leads to a known position - prevent circles
4. do this next step
UNIT – V
PART - A
PART - B
1. Explain branch and bound?
Ans:
The term Branch-and-Bound refers to all the state space methods in which all
children of the E-node are generated before any other live node can become the
Enode. the searching techniques that are commonly used in Branch-and-Bound
method.
The searching techniques that are commonly used in Branch-and-Bound
method are:
i. LC search
ii. 15 – puzzle problem
iii. LC control abstraction
iv. Bounding
v. FIFO branch and bound
vi. LC branch and bound
The minimum spanning tree of a planar graph. Each edge is labeled with its weight,
which here is roughly proportional to its length.
Minimum-cost subgraph
If the weights are non-negative, then a minimum spanning tree is in fact the minimum-
cost subgraph connecting all vertices, since subgraphs containing cycles necessarily
have more total weight.
Cycle property
For any cycle C in the graph, if the weight of an edge e of C is larger than the weights
of other edges of C, then this edge cannot belong to an MST. Assuming the contrary,
i.e. that e belongs to an MST T1, then deleting e will break T1 into two subtrees with
the two ends of e in different subtrees. The remainder of C reconnects the subtrees,
hence there is an edge f of C with ends in different subtrees, i.e., it reconnects the
subtrees into a tree T2 with weight less than that of T1, because the weight of f is less
than the weight of e.
Cut property
For any cut C in the graph, if the weight of an edge e of C is smaller than the weights
of other edges of C, then this edge belongs to all MSTs of the graph. Indeed, assume
the contrary, i.e., e does not belong to an MST T1. Then adding e to T1 will produce a
cycle, which must have another edge e2 from T1 in the cut C. Replacing e2 with e
would produce a tree T1 of smaller weight.
Algorithm
The first algorithm for finding a minimum spanning tree was developed by Czech
scientist Otakar Borůvka in 1926 (see Borůvka's algorithm). Its purpose was an
efficient electrical coverage of Moravia. There are now two algorithms commonly
used, Prim's algorithm and Kruskal's algorithm. All three are greedy algorithms that
run in polynomial time, so the problem of finding such trees is in FP, and related
decision problems such as determining whether a particular edge is in the MST or
determining if the minimum total weight exceeds a certain value are in P. Another
greedy algorithm not as commonly used is the reverse-delete algorithm, which is the
reverse of Kruskal's algorithm.
The problem can also be approached in a distributed manner. If each node is
considered a computer and no node knows anything except its own connected links,
one can still calculate the distributed minimum spanning tree.
UNIVERSITY QUESTIONS
Part - B
11.(a) (i) Define the asymptotic notations used for best case average case and worst case
analysis of
algorithms
(ii) Write an algorithm for finding maximum element of an array , perform best , worst
and average
case complexity with appropriate order notations.
(or)
(b) Write an algorithm to find mean and variance of an array perform best, worst and
average case
complexity, defining the notations used for each type of analysis.
12. (a) Derive the recurrence equation for Fibonacci series. Perform Complexity analysis
for the same.
(or)
(b) Explain in detail, the techniques for algorithm visualization.
13. (a) Explain in detail quick sorting method. Provide a complete analysis of quick sort.
//see Anany Levitin book
(or)
(b) Explain in detail merge sort. illustrate the algorithm with a numeric example. Provide
complete
analysis of the same. // see Anany Levitin book
14 (a) Apply Prim's Algorithm and Kruskal algorithm to the graph to obtain minimum
spanning tree. Do
these algorithms generate same output – Justify // see Anany Levitin book
(or)
(b) Solve the following instance of the single-source shortest paths problem with vertex a
as the source.
// see anany levitin book for graph. Write the algorithm for the above problem
15. (a) Explain N-queens problem with an algorithm. Explain why backtracking is
defined as a default
procedure of last resort for solving problems. (or)
(b) job 1 job 2 job 3 job 4
a 9 2 7 8
b 6 4 3 7
c 5 8 1 8
d 7 6 9 4
Consider the above matrix for assignment problem involving persons and jobs.
Explain in detail how
branch and bound technique is useful is solving assignment problems
TWO MARKS ANSWER:
1. The function f(n)=O(g(n)) iff there exists positive constants C and no such that
f(n)<=c*g(n) for all n, n>= no.
2. Sorting, searching, numerical, string matching, geometric, combinatorial, graph
problems.
3. The Efficiency of an algorithm is based on the parameter on which the input size
depends upon. In most of the problems selection of such parameter is straight
forward. For ex it will be the size of the list for a problem of sorting, searching,
and similar problems.
4. The average case time complexity of linear search is Cavg(n)=P(n+1)/2 + n(1-P).
Cavg(n) is prob of successful search.
5. Scan the array to find its smallest element and swap it with the first time with the
1st element. Then starting with the 2nd element scan the entire list to find the
smallest element and swap it with the second element. Continuing in this fashion
to sort the entire list.
6. 1.select an unvisited node V, visit it and treat as the current node
2.find an unvisited neighbor of the current node, visit it, and make it the new
current node. if there are more than one unvisited neighbors the n resolve the tie
by following the alpha order.
3.if the current node has no unvisited neighbors, back track to its parent and make
it a new current node.
4.Repeat steps 2 & 3 until no more nodes can be visited.
5.Repeat steps 1 for the remaining nodes.
7. Transform and conquer is the 4th alg design and problem solving strategy.
Transform and conquer is an alg strategy in which the problem is solved by
applying transformations. There are three variations of this approach .1.instance
simplification, 2.representation change, 3.problem reduction.
8. An AVL tree is a binary tree in which the balance factor of every node which is
defined as the difference between the heights of the node’s and right sub tree is
either 0 or 1 or -1.(height of empty tree is -1).
9. NO, backtracking always does not produce optimal solution.
10. Branch and Bound is an alg design tech that enhances the idea of generating a
state space tree with the idea of estimating the best value obtainable from a
current node of the decision tree . if such an element is not superior to the
best solution seen upto that point in the processing of node is eliminated from
further considerations.
Part –B
11. (a)
(i) Big Oh:
The function f(n) = O(g(n)) iff there exist positive constants C and no such that
f(n)C * g(n) for all n, n , n0.
Omega:
The function f(n) =W (g(n)) iff there exist positive constant C and no such that f(n) C
* g(n) for all n, n n0.
Theta
The function f(n) =(g(n)) iff there exist positive constant C1, C2, and no such that
C1 g(n), f(n) C2 g(n) for all n, n n0.
Little Oh
The function f(n) = 0(g(n)) Iff Lim f(n) = 0 n - g(n)
Little omega The function f(n) = (g(n)) Iff Lim g(n) = 0 n - f(n)
11.(ii)
The problem is to find the maximum and minimum items in a set of n elements.
Though this problem may look so simple as to be converted it allows us to
demonstrate divide and conquer in simple setting.
Iterative algorithm
Algorithm straightmaxmin(a,n,max,min)
{
max:=min:=a[1];
for I:= 2 to n do
{
if(a[I]>max) then max:=a[I];
if(a[I]<min) then min := a[I];
}
}
Recursive algorithm
Algorithm maxmin(I,j,max,min)
{
if(I==j) then max:=min:=a[I];
else if (I=j-1) then
{
if(a[I]<a[j]) then
{
max:=a[j];
min:=a[I];
}
else
{
max:=a[I];
min:=a[j];
}}
else
{
mid:=(I+j)/2;
maxmin(I,mid,max,min);
maxmin(mid+1,j,max1,min1);
if ( max< max1) then max:= max1;
if(min > min1) then min:= min1;
}
}
12. (a) - An algorithm is said to be recursive if the same algorithm is invoked in the
body. An algorithm that calls itself is Direct recursive. Algorithm A is said to be indeed
recursive if it calls another algorithm, which in turn calls A.
- Recurrence equation of Fibonacci series
- int fibnum(int p)
{
if(p==1 || p==0 )
return(p);
else
return (fibnum(p-1)+fibnum(p-2));
}
13. (b) In merge sort the elements are to sorted in non decreasing order. Given a
sequence of n elements that is a[1],a[2]….a[n] the general idea is to magine them split
into 2 sets a[1],a[2],…..a[n/2] and a[n/2]+1,……,a[n].
each set is individually sorted and the resulting sorted sequence are merge to produce a
single sorted sequence of n elements. The time complexity is O(n log n) for worst case.
Insertion sort works exceedingly fast on arrays of less than 16 elements, though for
large n its computing time is O(n2).
The time complexity and space complexity of traveling salesperson problem is
Time complexity is O (n2 2n).
Space complexity is O (n 2n).
15. (b) The term Branch-and-Bound refers to all the state space methods in which all
children of the E-node are generated before any other live node can become the
Enode. the searching techniques that are commonly used in Branch-and-Bound
method.
The searching techniques that are commonly used in Branch-and-Bound
method are:
i. LC search
ii. 15 – puzzle problem
iii. LC control abstraction
iv. Bounding
v. FIFO branch and bound
vi. LC branch and bound
UNIVERSITY QUESTION PAPER
B.E/ B.Tech. DEGREE EXAMINATION, NOVEMBER 2005.
04 SEMESTER
CS1201 – DESIGN AND ANALYSIS OF ALGORITHMS.
Time: 3 Hrs.
Max.marks:100
PART A (Answer ALL questions)
10* 2=20
PART B
5*16=80
11. (i) Explain the necessary steps for analyzing efficiency of recursive algorithm
with example.
(OR)
(ii) What is empirical analysis of an algorithm? Discuss its strength and
weakness?
12. (i) Describe the steps in analyzing and coding an algorithm.
(OR)
(ii) Discuss the fundamentals of analysis framework and notations Used in
algorithm design.
13. (i) Explain Quick sort algorithm with suitable example.
(OR)
(ii) Give a suitable example and explain the Breadth first search And Depth first
search algorithms.
14. (i) Define AVL tree. Explain the construction sequence of AVL tree with a
simple example.
(OR)
(ii) Define spanning tree. Discuss the design steps in Prim’s Algorithm to
construct minimum spanning
tree with an ex.
15.(i) Explain Subset sum problem and discuss the possible solution strategies
using backtracking.
(OR)
(ii) Discuss the solution for Traveling salesman problem using Branch and bound
techniques.
PART B ANSWERS
11. (i)
1. Space Complexity:
The space complexity of an algorithm is the amount of memory it needs to run to
completion.
algorithm using Recursive function to fine sum of n numbers
Algorithm Rsum (a,n)
{
If(n_ 0) then
Return 0.0;
Else
Return Rsum(a, n- 1) + a(n);
}
2. Time Complexity
The time complexity of an algorithm is the amount of computer time it needs to run to
completion.
3. Asymptotic Notation
4. Performance measurement
5. Practical Complexities
15. (i) - Given n distinct positive numbers usually called as weights , the problem
calls for finding all the combinations of these numbers whose sums are m. To solve
any problem using backtracking, it requires that all the solutions satisfy a complex set
of constraints. They are:
iii. Explicit constraints.
iv. Implicit constraints.
They are rules that restrict each xi to take on values only from a give set. They depend
on the particular instance I of the problem being solved. All tuples that satisfy the
explicit constraints define a possible solution space.They are rules that determine
which of the tuples in the solution space of I satisfy the criteria function. It describes
the way in which the xi must relate to each other.
15. (ii) The term Branch-and-Bound refers to all the state space methods in which all
children of the E-node are generated before any other live node can become the
Enode. the searching techniques that are commonly used in Branch-and-Bound
method.
The searching techniques that are commonly used in Branch-and-Bound
method are:
i. LC search
ii. 15 – puzzle problem
iii. LC control abstraction
iv. Bounding
v. FIFO branch and bound
vi. LC branch and bound
PART B
5*16=80
11 . (a) (i) Elaborate the various asymptotic metrics used to evaluate the efficiency of
the algorithm.
(ii) Use the most appropriate notation to indicate the time efficiency class of a
sequential search
(1) In worst case (2) In the best case (3) In the average case
(or)
(b) Specify the Euclid algorithm, the consecutive integer checking algorithm and the
middle school algorithm for computing the GCD of two integer numbers. Which of them
is simpler? Which is more efficient? Why?
12 . (a) Consider the following Algorithm:
ALGORITHM Secret(A[0…n-1])
// INPUT: An array A[0..n-1] of n real numbers
Minval A[0]; Maxvala[0];
For i 1 to n-1 do
If A[i]< minval
Minval A[i];
If A[i]> maxval
maxval A[i];
return maxval-minval;
(i) What does this algorithm Compute?
(ii) What is the Basic operation?
(iii) How many times is the basic operation computed?
(iv) What is the efficiency class of this algorithm?
(v) Suggest an improvement or a better algorithm altogether and indicate the
efficiency class . If you cant do in , prove that in fact it Cant be done.
(or)
(b) Consider the following recursive algoritm for computing the sum of the 1st n
cubes :S(n)=13+23+….+n3;
ALGORITHM S(n)
// I/P : A +ve integer n;
// o/p: The sum of the first n cubes.
If n==1 return 1
Else return S(n-1) + n*n*n
(i)Set up and solve a recurrence relation for the number of the algorithm basic
operation is executed.
(ii) How does the algorithm compared with the straight forward non-recursive algorithm
for computing this function?
14 . (a) (i) Describe the Prim’s Algorithm for finding the minimum cost spanning tree.
(ii) Apply the Prim’s Algorithm to the following graph:
/(b) For each of the following lists , construct an AVL tree by inserting their elements
successfully , starting with an empty tree
(i) 1,2,3,4,5,6 (ii) 6,5,4,3,2,1 (iii) 3,6,5,1,2,4
15 . (a) Using Backtracking enumerate how can you solve the following problems:
(i) 8-Queens Problem (ii) Hamiltonian circuit problem
(or)
(b) (i) solve the following instances of the knapsack problem by branch and
bound technique
ITEM WEIGHT VALUES
1 10 $100
2 7 $63
3 8 $56
4 4 $12
W=16
(ii) Give an ex for the best case input for the branch and bound algorithm for
the assignment problem.
(iii) In The best case , how many nodes will be in the state space tree of the
branch and bound algorithm for the assignment problem.
PART B ANSWERS
11.(a)
(i) Big Oh:
The function f(n) = O(g(n)) iff there exist positive constants C and no such that
f(n)C * g(n) for all n, n , n0.
Omega:
The function f(n) =W (g(n)) iff there exist positive constant C and no such that f(n) C
* g(n) for all n, n n0.
• Theta
The function f(n) =(g(n)) iff there exist positive constant C1, C2, and no such that
C1 g(n), f(n) C2 g(n) for all n, n n0.
Little Oh
The function f(n) = 0(g(n)) Iff Lim f(n) = 0 n - g(n)
Little omega The function f(n) = (g(n)) Iff Lim g(n) = 0 n - f(n)
(ii) – Definition for sequential search- It compares given element with all the
elements in an array
- Algorithm for sequential search
- Briefly explain about efficiency class for sequential search
15. (a) Backtracking is used to solve problems with tree structures. Even problems
seemingly remote to trees such as a walking a maze are actually trees when the
decision 'back-left-straight-right' is considered a node in a tree.
(i) - 8-Queens Problems
- The problem is to place 8 queens on a 8 x 8 chessboard so that no two queen
“attack” that is, so that no two of them are on the same row, column or on the
diagonal.
- Algorithm for solving 8-Queen problem
- Explain some possible cases
(ii) A Hamiltonian path or traceable path is a path that visits each vertex exactly
once. A graph that contains a Hamiltonian path is called a traceable graph. A graph is
Hamilton-connected if for every pair of vertices there is a Hamiltonian path between
the two vertices. A Hamiltonian cycle, Hamiltonian circuit, vertex tour or graph cycle
is a cycle that visits each vertex exactly once (except the vertex which is both the start
and end, and so is visited twice). A graph that contains a Hamiltonian cycle is called a
Hamiltonian graph. Similar notions may be defined for directed graphs, where each
edge (arc) of a path or cycle can only be traced in a single direction
15. (b) (i)The term Branch-and-Bound refers to all the state space methods in which all
children of the E-node are generated before any other live node can become the Enode.
the searching techniques that are commonly used in Branch-and-Bound method.
The searching techniques that are commonly used in Branch-and-Bound
method are:
i. LC search
ii. 15 – puzzle problem
iii. LC control abstraction
iv. Bounding
v. FIFO branch and bound
vi. LC branch and bound
(ii) Given n objects and a knapsack or bag. Object I has a weight wi and the knapsack
has the capacity m. If a fraction xi 0<xi<1 of object i is placed in to knapsack then a
profit of pixi earned. The objective is to obtain a filling of the knapsack that maximizes
the total profit earned. Since the knapsack capacity is m, we require the total weight of
all chosen objects to be almost m.
PART B — (5 x 16 = 80 marks)
Or
(b) Explain in detail about mathematical analysis of non-recursive algorithm with
suitable examples. (16)
12. (a) Describe in detail about merge sort algorithm and justify the benefits of merge
sort with suitable example. (16)
Or
(b) (i) Explain in detail about Kruskal's algorithm. (8)
(ii) Find the minimum spanning tree using Krushal's algorithm with example. (8)
13. (a) Explain in detail about Warshall's algorithm with suitable example. (16)
Or
(b) Explain an algorithm to find optimal binary search tree with example. (16)
14. (a) (i) Explain the algorithm for Knapsack problem according to backtracking
problem. (5)
(ii) Explain in detail about Hamiltonian circuit problem. (11)
Or
(b) (i) Explain in detail about subset-sum problem with suitable example.(10)
(ii) Given a set S = {1,3,4,5} and X = 8. Find subset sum using backtracking
problem. (6)
(ii) A Hamiltonian path or traceable path is a path that visits each vertex exactly once.
A graph that contains a Hamiltonian path is called a traceable graph. A graph is
Hamilton-connected if for every pair of vertices there is a Hamiltonian path between
the two vertices. A Hamiltonian cycle, Hamiltonian circuit, vertex tour or graph cycle
is a cycle that visits each vertex exactly once (except the vertex which is both the start
and end, and so is visited twice). A graph that contains a Hamiltonian cycle is called a
Hamiltonian graph. Similar notions may be defined for directed graphs, where each
edge (arc) of a path or cycle can only be traced in a single direction
(b) (i) The subset sum problem is a good introduction to the NP-complete class of
problems. There are two reasons for this
• It is a decision and not an optimization problem
• It has a very simple formal definition and problem statement.
Although the subset sum problem is a decision problem, the cases when an approximate
solution is sufficient have also been studied, in the field of approximations algorithms;
PART B 5*16=80
11. (a) (i) What are the important problem types focussed by the researchers? Explain
any 2 with eg.
(ii)What is Empirical Analysis of an algorithm? Discuss its strength and
weakness
(or)
(b) (i) Discuss the Fundamentals of Analyse framework.
(ii) Explain the various Asymptotic Notations used in Algorithm design.
12. (a)Discuss the general plan for analysing the efficiency of Non-recursive Algorithm.
Write an algorithm to find the number of binary digits in the binary representation
of a positive decimal
integer and analyse its efficiency. (or)
(b) What is the principle alternative to Mathematical analysis of an algorithm?
Explain the steps in analysing the efficiency of this analysis with eg.
13. (a) Find the number of comparison made by the sentinel version of sequential
search algorithm for
(i) In worst case and (ii) In Average case. (or)
(b) Give a suitable eg and explain the Depth First Search algorithm.
14. (a) (i) Define Heap.Explain the properties of Heap.
(ii) With a simple eg Explain heap sort algorithm. (or)
(b) Define Spanning tree. Discuss the design steps in Kruskal’s algorithm to
construct minimum spanning tree with an eg.
15. (a) Explain subset sum problem and discuss the possible solution strategies using
Backtracking.
(or)
(b) Discuss the solution for Knapsack problem using Branch and Bound Technique.
2. There are two kinds of efficiency: time efficiency and space efficiency. Time
efficiency indicates how fast an algorithm in question runs; space efficiency
deals with the extra space the algorithm requires.
PART B ANSWERS
11 (a) (i) Important problem types are
Sorting
Searching
String Processing
Graph problem
Combinatorial Problems
Geometric Problems
Numerical Problems(Refer page no 19 of Anany Levitin)
(ii) A general plan for empirical analysis of algorithm efficiency:
1. Understand the experiment’s purpose
2. Decide on the efficiency metric M to be measured and the measurement
unit
3. Decide on characteristics of the input sample
4. Prepare a program implementing the algorithm for the experimentation
5. Generate a sample of inputs
6. Run the algorithm on the sample’s inputs and record the data observed
7. Analyze the data obtained(Refer page no 85 from Anany Levitin)
11. (b) (i) Analysis Framework:
-Measuring an input’s size
-Unit for measuring running time
- Order of growth
-Worst-case, Best-case and Average –case Efficiencies
14. (a) (i) Heap -A heap can be defined as a binary tree with keys assigned to its nodes
provided the following two conditions are met
1. the binary tree is essentially complete
2. The Key at each node is greater than or equal to the keys at its children
15.(a) The subset sum problem is a good introduction to the NP-complete class of
problems. There are two reasons for this
• It is a decision and not an optimization problem
• It has a very simple formal definition and problem statement.
Although the subset sum problem is a decision problem, the cases when an approximate
solution is sufficient have also been studied, in the field of approximations algorithms;
15. (b) (i)The term Branch-and-Bound refers to all the state space methods in which all
children of the E-node are generated before any other live node can become the Enode.
the searching techniques that are commonly used in Branch-and-Bound method.
The searching techniques that are commonly used in Branch-and-Bound
method are:
i. LC search
ii. 15 – puzzle problem
iii. LC control abstraction
iv. Bounding
v. FIFO branch and bound
vi. LC branch and bound
(ii) Given n objects and a knapsack or bag. Object I has a weight wi and the knapsack
has the capacity m. If a fraction xi 0<xi<1 of object i is placed in to knapsack then a
profit of pixi earned. The objective is to obtain a filling of the knapsack that maximizes
the total profit earned. Since the knapsack capacity is m, we require the total weight of
all chosen objects to be almost m.
PART B
11.a)Explain how time complexity is calculated .Give an example
(OR)
b)Elaborate on Asymptotic Notations with examples
12.a)With a suitable algorithm,explain the problem of finding the maximum and
minimum items in a set of n elements (OR)
b)Explain Merge Sort Problem using divide and conquer technique. Give an example
13.a) Write down and explain the algorithm to solve all pairs shortest paths problem
(OR)
b)Explain how dynamic programming is applied to solve travelling salesperson
problem
14.a)Describe the backtracking solution to solve 8-Queens problem
(OR)
b)With an example, explain Graph coloring algorithm
15.a) Explain in detail the Graph Traversals
(OR)
b) With an example, explain how the branch and bound technique is used to solve 0/1
Knapsack problem