CS6402 Design and Analysis of Algorithms Question Bank
CS6402 Design and Analysis of Algorithms Question Bank
2. Write an algorithm to compute the greatest common divisor of two numbers. [M – 17]
gcd(a, b)
{
if (a == 0 || b == 0)
return 0;
if (a == b)
return a;
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
5. What is the formula used in Euclid‘s algorithm for finding the greatest common divisor of two
numbers? [N – 16]
Euclid‗s algorithm is based on repeatedly applying the equality
Gcd[m,n]=gcd[n,m mod n] until m mod n is equal to 0, since
gcd[m,0]=m.
6. What are the three different algorithms used to find the gcd of two numbers? [M – 15]
The three algorithms used to find the gcd of two numbers are
• Euclid‗s algorithm
• Consecutive integer checking algorithm
• Middle school procedure
7. What are the fundamental steps involved in algorithmic problem solving? The
fundamental steps are
• Understanding the problem
• Ascertain the capabilities of computational device
• Choose between exact and approximate problem solving
• Decide on appropriate data structures
• Algorithm design techniques
• Methods for specifying the algorithm
• Proving an algorithms correctness
• Analyzing an algorithm
• Coding an algorithm
24. Mention the useful property, which can be applied to the asymptotic notations and its use? [M – 15]
If t1[n] ε O[g1[n]] and t2[n] ε O[g2[n]] then t1[n]+t2[n] ε max {g1[n],g2[n]} this property is also true for Ω
and θ notations. This property will be useful in analyzing algorithms that comprise of two consecutive
executable parts.
27. Give the General strategy divide and conquer method. [M – 16]
A divide and conquer algorithm works by recursively breaking down a problem into two or more
sub-problems of the same [or related] type [divide], until these become simple enough to be solved
directly [conquer].
Divide-and-conquer algorithms work according to the following general plan:
a. A problem is divided into several sub problems of the same type, ideally of about
equal size.
b. The sub problems are solved [typically recursively, though sometimes a different
algorithm is employed, especially when sub problems become small enough].
c. If necessary, the solutions to the sub problems are combined to get a solution to the
original problem.
Example: Merge sort, Quick sort, Binary search, Multiplication of Large Integers and Strassen‘s
Matrix Multiplication.
29. Devise an algorithm to make a change for 1655 using the Greedy strategy. The coins available are
{1000, 500, 100, 50, 20, 10, 5}. [M -17]
Algorithm:
while( there are more coins and the instance is not solved) {
grab the largest remaining coin; // selection procedure
if(adding the coin makes the change exceed the amount owed )
reject the coin; // feasibility check
else
add the coin to the change;
if( the total value of the change equals the amount owed )
// solution check the instance is solved;
}
Solution for the given instance 1655 = 1000 + 500 +100 + 50 + 5
PART – B (16 Marks)
1. Explain closest pair and convex hull problem with example. [M – 15]
2. Compare and contrast between quick sort and merge sort with the following numbers 43, 22, 67, 10, 34, 55,
88, 71 [N - 14]
3. State and Explain the Merge sort algorithm and give the recurrence relation and efficiency. [M – 16]
4. Explain the method used for performing multiplication of two large integers. Explain how divide conquer
Method can be used to solve the same [M – 16]
5. Explain Floyd‘s algorithm with example. [N – 15]
6. Explain the memory functions of knapsack problem with example [M – 15]
7. Explain optimal binary search tree with example. [N – 14]
8. Explain Kruskal‘s algorithm with example. [M – 15]
9. A pair contains two numbers, and its second number is on the right side of the first ne in an array. The
difference of a pair is the minus result while subtracting the second number from the first one. Implement a function
which gets the maximal difference of all pairs in an array (using Divide and Conquer method). [M – 15]
10. Find whether the given string follows the specified pattern and return 0 or 1 accordingly.
Examples:
i. Pattern : "abba", input:"redblueredblue" should return 1
ii. Pattern : "abba", input:"asdasdasdasd" should return 1
iii. Pattern : "aabb", input:"xyzabcxyzabc" should return 1 [M – 17]
11. What is divide and conquer strategy and explain binary search with suitable example
problem. [M – 17]
12. Explain the algorithm for Quicksort. With an example show that Quicksort is not a stable sorting algorithm
[N – 16]
13. There are 4 people who need to be assigned to execute 4 jobs (one person per job) and the problem is to
find an assignment with minimum total cost. The assignment costs is given below, solve the assignment problem
by exhaustive search. [N – 16]
6. Write the difference between the Greedy method and Dynamic programming.
• Greedy method
1. Only one sequence of decision is generated.
2. It does not guarantee to give an optimal solution always.
• Dynamic programming
1. Much number of decisions is generated.
2. It definitely gives an optimal solution always.
13. How are the vertices not in the tree split into?
The vertices that are not in the tree are split into two sets
• Fringe: It contains the vertices that are not in the tree but are adjacent to at least one tree vertex.
• Unseen: All other vertices of the graph are called unseen because they are yet to be affected by
the algorithm.
14. What are the operations to be done after identifying a vertex u* to be added to the tree?
After identifying a vertex u* to be added to the tree, the following two operations need to be performed
• Move u* from the set V-VT to the set of tree vertices VT.
• For each remaining vertex u in V-VT that is connected to u* by a shorter edge than the u‗s current
distance label, update its labels by u* and the weight of the edge between u* and u, respectively.
19. Give the upper bound and lower bound of matrix multiplication algorithm?
Upper bound: The given algorithm does n*n*n multiplication hence at most n*n*n multiplication are
necessary.
Lower bound: It has been proved in the literature that at least n*n multiplication is necessary.
10. Write the Huffman's algorithm. construct the Huffman's tree for the following data and obtain its Huffman's
code. [M - 17]
Character A B C D E -
Probability 0.5 0.35 0.5 0.1 0.4 0.2
11. Discuss about the algorithm and Pseudocode to find the Minimum Spanning Tree using Prim's Algorithm.
Find the Minimum Spanning tree for the graph show below. [M - 16]
12. Find all the Solution to the travelling salesman problem (cities and distances shown below) by exhaustive
search. Give the optimal solution. [M - 16]
13. Solve the all pairs shortest path problem for the digraph with the following weight matrix: [N – 16]
14. Apply Kruskal’s algorithm to find a minimum spanning tree of the following graph. [N-16]
UNIT- IV: ITERATIVE IMPROVEMENT
1. Define – Linear programming
maximize 3x + 5y
subject to x+ y≤4
x≥0, y≥0.Variables u and v, transforming inequality constraints into equality constrains, are called
slack variables
2. What is basic solution?
A basic solution to a system of m linear equations in n unknowns [n ≥ m] is obtained by setting n –
m variables to 0 and solving the resulting system to get the values of the other m variables. The
variables set to 0 are called non basic; the variables obtained by solving the system are called
basic. A basic solution is called feasible if all its [basic] variables are nonnegative.
10. State and prove Maximum flow and minimum cut Theorem. [N – 16]
UNIT – V : COPING WITH THE LIMITATIONS OF ALGORITHM POWER
2. Define - 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. The principle idea is to construct solutions one component at a time and evaluate such partially constructed
candidates
7. Why the search path in a state-space tree of a branch and bound algorithm is terminated?
• The value of the node‗s bound is not better than the value of the best solution.
• The node represents no feasible solutions because the constraints of the problem are already violated.
• The subset of feasible solutions represented by the node consists of a single point.
14. What is the manner in which the state-space tree for a backtracking algorithm is constructed?
In the majority of cases, a state-space tree for backtracking algorithm is constructed in the manner of depth-
first search. If the current node is promising, its child is generated by adding the first remaining legitimate
option for the next component of a solution, and the processing moves to this child.
21. Give the formula used to find the upper bound for knapsack problem.
A simple way to find the upper bound ‗ub‗ is to add ‗v‗, the total value of the items already selected, the product
of the remaining capacity of the knapsack W-w and the best per unit payoff among the remaining items, which is
vi+1/wi+1
ub = v + [W-w][ vi+1/wi+1]