CS8451 Design and Analysis of Algorithms QBank (Downloaded From Annauniversityedu - Blogspot.com)
CS8451 Design and Analysis of Algorithms QBank (Downloaded From Annauniversityedu - Blogspot.com)
CS8451 Design and Analysis of Algorithms QBank (Downloaded From Annauniversityedu - Blogspot.com)
UNIT – I
INTRODUCTION
3. What are important problem types? (or) Enumerate some important types of problems?
(i) Sorting (ii) Searching (iii) Numerical problems (iv) Geometric problems (v) Combinatorial
Problems (vi) Graph Problems (vii) String processing Problems
11. Compare the order of growth n(n-1)/2 and n2. [May/June 2016]
n n(n-1)/2 n2
Polynomial Quadratic Quadratic
1 0 1
2 1 4
4 6 16
8 28 64
10 45 102
102 4950 104
Complexity Low High
Growth Low high
n(n-1)/2 is lesser than the half of n2
15. What do you mean by time complexity and space complexity of an algorithm? [Nov/Dec 2012]
Time complexity indicates how fast the algorithm runs. Space complexity deals with extra memory
it require. Time efficiency is analyzed by determining the number of repetitions of the basic operation as a
function of input size. Basic operation: the operation that contributes most towards the running time of the
algorithm The running time of an algorithm is the function defined by the number of steps (or amount of
memory) required to solve input instances of size n.
18. Give the Euclid’s algorithm for computing gcd(m, n) [May/June 2016]
Algorithm Euclid_gcd(m, n)
//Computes gcd(m, n) by Euclid’s algorithm
//Input: Two nonnegative, not-both-zero integers m and n
//Output: Greatest common divisor of m and n
while n ≠ 0 do
r ←m mod n
m←n
n←r
return m
Example: gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.
35. Write an algorithm to find the number of binary digits in the binary representation of a positive
decimal integer. [April/May 2015]
Algorithm Binary(n)
//Input: A positive decimal integer n
//Output: The number of binary digits in n’s binary representation
count ←1
while n > 1 do
count ←count + 1
n←[n/2]
Downloaded from: annauniversityedu.blogspot.com
return count
37. What are six steps processes in algorithmic problem solving? [Nov/Dec 2009]
Understanding the problem
Decision making on - Capabilities of computational devices, Choice of exact or approximate problem
solving, Data structures
Algorithmic strategies
Specification of algorithm
Algorithmic verification
Analysis of algorithms
40. What are the components of fixed and variable part in space complexity? The space requirements
S(p) is given by following formula
S(p)= C + Sp
C - fixed part that denotes the space of inputs and outputs, this space is the amount of space taken by
instructions, variables and identification
Sp - denotes variable part of the space. It denotes the space requirements based on particular problem
instance
51. List the factors which affects the running time of the algorithm.
A. Computer
B. Compiler
C. Input to the algorithm
i. The content of the input affects the running time
ii. Typically, the input size is the main consideration.
52. What are the three different algorithms used to find the gcd of two numbers?
The three algorithms used to find the gcd of two numbers are
1. Euclid's algorithm
Sorting
Searching
String processing
Graph problems
Combinatorial problems
Geometric problems
Numerical problems
55. 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 and Coding an algorithm
56. Give an non-recursive algorithm to find out the largest element in a list of n numbers.
ALGORITHM MaxElement(A[0..n-1])
//Determines the value of the largest element in a given array
Input:An array A[0..n-1] of real numbers
//Output: The value of the largest element in A maxval  a[0]
for I  1 to n-1 do
if A[I] > maxval return maxval
 A[I] return maxval
59. Write a recursive algorithm for computing the nth fibonacci number.
ALGORITHM F(n)
// Computes the nth Fibonacci number recursively by using the definition
// Input A non-negative integer n
// Output The nth Fibonacci number
T(n) = g(n)
PART- B
UNIT-I
1. What are the important problem types focused by the researchers? Explain all the types with example
2. What is empirical analysis of an algorithm? Discuss its strength and weakness.
3. Discuss the fundamentals of analysis framework.
4. Explain the various asymptotic notations used in algorithm techniques.
5. Describe briefly the notions of complexity of algorithm.
6. What is pseudo code? Explain with an example.
7. Explain various criteria used for analyzing algorithms.
8. Discuss briefly the sequence of steps in designing and analyzing algorithm
9. Develop the general framework for analyzing the efficiency of algorithm
10. Explain the fundamentals of algorithmic problem solving with algorithm design and analysis process
diagram
11. Elaborate the simple factoring algorithm with example .
12. Discuss the Euclid’s algorithm with example.
13. Outline the steps in analyzing & coding an algorithm.
14. Explain some of the problem types used in the design of algorithm.
15. Discuss the fundamentals of analysis framework.
16. Elaborate the various asymptotic notations used in algorithm design.
17. Explain the general framework for analyzing the efficiency of algorithm.
18. Outline the various Asymptotic efficiencies of an algorithm.
19. Discuss the basic efficiency classes.
20. Explain briefly the concept of algorithmic strategies.
21. Describe briefly the notions of complexity of an algorithm.
22. What is Pseudo-code? Explain with an example.
23. Find the complexity C(n) of the algorithm for the worst case, best case and average case. (Evaluate
average case complexity for n=3, Where n is the number of inputs)
24. Set up & solve a recurrence relation for the number of key comparisons made by above pseudo code.
UNIT – II
BRUTE FORCE AND DIVIDE AND CONQUER
1. Define the divide and conquer method.
6. Derive the complexity of Binary Search algorithm. [April/May 2015, Nov/Dec 2016]
In conclusion we are now able completely describe the computing time of binary search by giving
formulas that describe the best, average and worst cases.
Successful searches Unsuccessful searches
Best case - (1) Best case, Average case, Worst case - (log2 n)
Average case - (log2 n)
Worst case - (log2 n)
10. Give the General strategy divide and conquer method. [May/June 2016]
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 problem is divided into several subproblems of the same type, ideally of about equal size.
The subproblems are solved (typically recursively, though sometimes a different algorithm is
employed, especially when subproblems become small enough).
If necessary, the solutions to the subproblems 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.
11. What is the Quick sort? Write the Analysis for the Quick sort.
Quicksort is dividing and conquer strategy that works by partitioning its input elements according
to their value relative to some preselected element (pivot). It uses recursion and the method is also called
partition –exchange sort. O(nlogn) in average and best cases, O(n2) in worst case
12. What is Merge sort and is insertion sort better than the merge sort?
Merge sort is divide and conquer strategy that works by dividing an input array in to two halves, sorting
them recursively and then merging the two sorted halves to get the original array sorted Insertion sort
works exceedingly fast on arrays of less than 16 elements, though for large ‘n’ its computing time is O(n2).
23. Define the single source shortest path problem. [May/June 2016]
Dijkstra’s algorithm solves the single source shortest path problem of finding shortest paths from a
given vertex (the source), to all the other vertices of a weighted graph or digraph. Dijkstra’s algorithm
provides a correct solution for a graph with non negative weights.
27. Give the benefit of application of brute force technique to solve a problem.
With the application of brute force strategy, the first version of an algorithm obtained can often be
improved with a modest amount of effort. So a first application of the brute force approach often results in
an algorithm that can be improved with a modest amount of effort.
30. What is the difference between quick sort and merge sort?
Both quicksort and mergesort use the divide-and-conquer technique in which the given array is
partitioned into sub arrays and solved. The difference lies in the technique that the arrays are partitioned.
For mergesort the arrays are partitioned according to their position and in quicksort they are partitioned
according to the element values.
UNIT - II
PART -B
1. Discuss the general plan for analyzing the efficiency of non recursive algorithms.
2. Write an algorithm for a given numbers to n generate the nth number of the Fibonacci sequences.
3. Explain the necessary steps for analyzing the efficiency of recursive algorithms.
4. Write short notes on algorithm visualization.
5. Design a recursive algorithm to compute the factorial function F(n) =n! for an arbitrary non negative
integer n also derive the recurrence relation.
6. Explain the general plan for mathematical analysis of recursive algorithms with example.
7. Explain algorithm visualization with examples.
8. Write an algorithm to find the number of binary digits in the binary representation of a positive decimal
integer and analyze its efficiency
9. Write an algorithm for finding of the largest element in a list of n numbers.
10. Differentiate mathematical analysis of algorithm and empirical analysis of algorithm.
11. Explain static algorithm visualization and dynamic algorithm visualization with example.
12. Explain algorithm animation with example
13. Write a pseudo code for divide & conquer algorithm for merging two sorted arrays in to a single
sorted one. Explain with example.
14. Construct a minimum spanning tree using Kruskal’s algorithm with your own example.
15. Explain about Knapsack Problem with example
16. Explain Dijikstra algorithm
17. Define Spanning tree. Discuss design steps in Prim’s algorithm to construct minimum spanning tree
with an example.
18. Explain Kruskal’s algorithm.
19. Explain about binary search with example.
2. Write down the optimization technique used for Warshall’s algorithm. State the rules and
assumptions which are implied behind that. [April/May 2015]
Warshall’s algorithm constructs the transitive closure of the given diagraph with n vertices through
a series of n by n Boolean matrices. This computation is done as follows
(0) (k1) (k) (n)
R ,...., R ,...., R ,. .. , R
The optimization technique used for Warshalls’s algorithm is based on construction of Boolean matrices.
The elements of this matrix can be generated using the formula
r(k) r(k1) or r(k-1) and r(k1)
ij ij ik kj
r (k ) ith jth (k)
where ij is the element in row and column of matrix R
5. Specify the algorithms used for constructing Minimum cost spanning tree.
Prim’s Algorithm
Kruskal’s Algorithm
11. Write the difference between the Greedy method and Dynamic programming.
Greedy Method Dynamic Programming
One sequence of decision is generated. Many number of decisions are generated.
It guarantee to give an optimal does not solution It definitely gives an optimal solution always.
always
12. List out the memory functions used under Dynamic Programming. [April/May 2015]
Memory function for binomial coefficient is
C(n, k) C(n 1, k 1) C(n 1, k)
and
C(n,0) C(n, n) 1
28. State time and space efficiency of OBST(Optimal Binary Search Tree).
Space efficiency is quadratic and Time efficiency is cubic.
35. Write the general algorithm for Greedy method control abstraction.
Algorithm Greedy (a, n)
{
solution=0;
for i=1 to n do
{
x= select(a);
if feasible(solution ,x) then
solution=Union(solution ,x);
}
return solution;
}
UNIT-III
PART- B
1. Discuss Brute force method with proper example .
2. Develop algorithm for selection sort and bubble sort with proper example .
3. Build a sequential searching algorithm with example .
4. Explain brute force string matching algorithm with example
5. Develop the divide and conquer algorithms with example .
6. Outline merge sort algorithm with example .
7. Plan the quick sort algorithm with example .
8. Explain binary search algorithm with example .
9. Discuss the binary tree traversals and related properties with example.
10. Explain insertion sort with example .
11. Explain Depth First Search and Breadth First Search .
12. Write an algorithm to sort a set of N numbers using insertion sort .
13. Trace the algorithm for the following set of number 20, 35, 18, 8 14, 41, 3, 39.
14. Mention any three search algorithms which is preferred in general? why?
15. Develop algorithm for Warshall’s & Floyd’s to find the optimal solution.
16. Explain about Multistage graphs with example.
17. Develop optimal binary search trees with example.
18. Explain 0/1 knapsack problem with example.
19. Discuss the solution for Travelling salesman problem using branch & bound technique.
A cut is said to be minimum in a network whose capacity is minimum over all cuts of the network.
7. Define preflow.
A preflow is a flow that satisfies the capacity constraints but not the flow conservation requirement
17. How many binary search trees can be formed with ‘n’ keys?
The total number of binary search trees with ‘n’ keys is equal to the nth Catalan number
c(n) = for n >0, c(0) = 1, which grows to infinity as fast as 4n/n1.5.
18. Give the algorithm used to find the optimal binary search tree.
ALGORITHM OptimalBST(P[1..n])
//Finds an optimal binary search tree by dynamic programming
//Input An array P[1..n] of search probabilities for a sorted list of ‘n’ keys
//Output Average number of comparisons in successful searches in the optimal //BST and table R of
subtrees’ roots in the optimal BST
for I 1 to n do
C[I,I-1] 0
C[I,I] P[I]
R[I,I] I
C[n+1,n] 0
for d 1 to n-1 do
for i 1 to n-d do
j i +d
minval
for k I to j do
if C[I,k-1]+C[k+1,j] < minval
minval C[I,k-1]+C[k+1,j]; kmin k
R[I,j] k
Sum P[I]; for s I+1 to j do sum sum + P[s]
C[I,j] minval+sum
Return C[1,n], R
19. List out three possible outcomes in 3 possible outcomes in solving an LP problem.
3 possible outcomes in solving an LP problem are
1. has a finite optimal solution, which may no be unique
2. unbounded: the objective function of maximization (minimization) LP problem is unbounded from
above (below) on its feasible region
3. infeasible: there are no points satisfying all the constraints, i.e. the constraints are contradictory
To find a flow-augmenting path for a flow x, consider paths from source to sink in the underlying undirected
graph in which any two consecutive vertices i,j are either:
• connected by a directed edge (i to j) with some positive unused capacity rij = uij – xij
– known as forward edge ( → )
OR
• connected by a directed edge (j to i) with positive flow xji
– known as backward edge ( ← )
If a flow-augmenting path is found, the current flow can be increased by r units by increasing xij by r on each
forward edge and decreasing xji by r on each backward edge, where
Let X be a set of vertices in a network that includes its source but does not include its sink, and let X,
the complement of X, be the rest of the vertices including the sink. The cut induced by this partition of
the vertices is the set of all the edges with a tail in X and a head in X.
Capacity of a cut is defined as the sum of capacities of the edges that compose the cut.
UNIT-IV
PART- B
UNIT – V
COPING WITH THE LIMITATIONS OF ALGORITHM POWER
2. Define Branch-and-Bound method. What are the searching techniques that are commonly used in
Branch-and-Bound?
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 E- node. The searching techniques that are
commonly used in Branch-and-Bound method are:
FIFO
LIFO
LC
Heuristic search
12. What is The Euclidean minimum spanning tree problem? [May/June 2016]
The Euclidean minimum spanning tree or EMST is a minimum spanning tree of a set of n points in
the plane where the weight of the edge between each pair of points is the Euclidean distance between those
two points. In simpler terms, an EMST connects a set of dots using lines such that the total length of all the
lines is minimized and any dot can be reached from any other by following the lines.
13. Draw the decision tree for comparison of three values. [Nov/Dec 2015]
15. State the reason for terminating search path at the current node in branch and bound algorithm.
[Nov/Dec 2016]
The value of the nodes bound is not better than the value of the best solution seen so far.
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 – here we
compare the value of the objective function for this feasible solution with that of the best solution
seen so far and update the latter with the former, if the new solution is better.
25. 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. If the current
node turns out to be non-promising, the algorithm backtracks to the node's parent to consider the next
possible solution to the problem, it either stops or backtracks to continue searching for other possible
solutions.
31. What are the tricks used to reduce the size of the state-space tree?
The various tricks are
a) Exploit the symmetry often present in combinatorial problems. So some solutions can be
obtained by the reflection of others. This cuts the size of the tree by about half.
b) Reassign values to one or more components of a solution
c) rearranging the data of a given instance.
32. What is the method used to find the solution in n-queen problem by symmetry?
The board of the n-queens problem has several symmetries so that some solutions can be obtained
by other reflections. Placements in the last n/2 columns need not be considered, because any solution with
the first queen in square (1,i), n/2 i n can be obtained by reflection from a solution with the first queen in
square (1,n-i+1)
33. What are the additional features required in branch-and-bound when compared to
backtracking?
Compared to backtracking, branch-and-bound requires: A way to provide, for every node of a state
space tree, a bound on the best value of the objective function on any solution that can be obtained by
adding further components to the partial solution represented by the node.
40. What are the requirements that are needed for performing Backtracking?
To solve any problem using backtracking, it requires that all the solutions satisfy a complex set of
constraints. They are:
i. Explicit constraints.
ii. Implicit constraints.
48. What are the factors that influence the efficiency of the backtracking algorithm?
The efficiency of the backtracking algorithm depends on the following four factors. They are:
i. The time needed to generate the next xk
ii. The number of xk satisfying the explicit constraints.
iii. The time for the bounding functions Bk
iv. The number of xk satisfying the Bk.
UNIT-V
1. Discuss backtracking with example.