Академический Документы
Профессиональный Документы
Культура Документы
UNIT I INTRODUCTION
2. What is algorithmics?
The study of algorithms is called algorithmics. Algorithmics is the science of
algorithms. It includes algorithm design, the art of building a procedure which can solve
efficiently a specific problem or a class of problem, algorithmic complexity theory, the
study of estimating the hardness of problems by studying the properties of algorithm that
solves them, or algorithm analysis, the science of studying the properties of a problem,
such as quantifying resources in time and memory space needed by this algorithm to
solve this problem. It is more than a branch of computer science. It is the core of
computer science and is said to be relevant to most of science, business and technology.
Problem to be solved
Algorithm
7. What is the formula used in Euclids algorithm for finding the greatest common
divisor of two numbers?
Euclids 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.
Example: gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.
28. Write worst case, avg. case and best case analysis for binary search.
Time complexity of Binary search
Best case Average case Worst case
(1) (log2 n) (log2 n)
29. Write worst case, avg. case and best case analysis for linear search.
Time complexity of Linear search
Best case Average case Worst case
(1) (n) (n)
34. Mention the useful property, which can be applied to the asymptotic notations.
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.
40. Write a recursive algorithm to find the number of binary digits in the binary
representation of an integer.
ALGORITHM BinRec(n)
Input A positive decimal integer n
Output The number of binary digits in ns binary representation
if n=1 return 1
else return BinRec(n/2)+1
ALGORITHM F(n)
//Computes n! recursively
//Input: A nonnegative integer n
//Output: The value of n!
if n = 0 return 1
else return F(n 1) * n
43. Write the General Plan for Analyzing the Time Efficiency of Nonrecursive
Algorithms
1. Decide on a parameter (or parameters) indicating an inputs size.
2. Identify the algorithms basic operation (in the innermost loop).
3. Check whether the number of times the basic operation is executed depends only on
the size of an input. If it also depends on some additional property, the worst-case,
average-case, and, if necessary, best-case efficiencies have to be investigated
separately.
4. Set up a sum expressing the number of times the algorithms basic operation is
executed.
5. Using standard formulas and rules of sum manipulation either find a closed form
formula for the count or at the least, establish its order of growth.
9 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A
44. Write the General Plan for Analyzing the Time Efficiency of Recursive Algorithms
1. Decide on a parameter (or parameters) indicating an inputs size.
2. Identify the algorithms basic operation.
3. Check whether the number of times the basic operation is executed can vary on
different inputs of the same size; if it can, the worst-case, average-case, and best-case
efficiencies must be investigated separately.
4. Set up a recurrence relation, with an appropriate initial condition, for the number of
times the basic operation is executed.
5. Solve the recurrence or, at least, ascertain the order of growth of its solution.
4. Bubble Sort
The bubble sorting algorithm is to compare adjacent elements of the list and exchange
them if they are out of order. By doing it repeatedly, we end up bubbling up the largest
element to the last position on the list. The next pass bubbles up the second largest
element, and so on, until after n 1 passes the list is sorted. Pass i (0 i n 2) of
?
bubble sort can be represented by the following: A0, . . . , Aj Aj+1, . . . , Ani1 | Ani . .
. An1
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:
1. A problem is divided into several subproblems of the same type, ideally of about
equal size.
12 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A
where
13 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A
16. Compare strassens algorithm and brute force algorithm for matrix multiplication.
strassens matrix multiplication algorithm
1. 7 multiplications 8 multiplications
2. Algorithm and implementation are not Algorithm and implementation are simple.
simple.
3. Time complexity is (n2.8). Time complexity is (n3).
4. Order of growth is better than brute Order of growth is not better than
force matrix multiplication algorithm. Strassens matrix multiplication algorithm.
5. It is faster than the standard matrix It is slower than Strassens matrix
multiplication algorithm and is useful in multiplication algorithm.
practice for large matrices.
7. Algorithm design technique is divide Algorithm design technique is brute force.
and conquer.
7. Algorithm works only for n=2k, Algorithm works for all n.
k=1,2,3,..
14 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A
3. How do you find the nth Fibonacci number? Write the algorithm.
Starting from x(0) = 0 and x(1) = 1, the series progresses infinitely as:
0,1,1,2,3,5,8,13...
// nth Fibonacci number finding algorithm by Dynamic programming
Fib(n)
if (n == 0)
return 0;
if (n == 1)
return 1;
else
return Fib(n-1) + Fib(n-2);
Let T(n) be the complexity of the above algorithm. T(n) can be written in the form of
a recurrence relation as: T(n)=T(n1)+T(n2) => n=n-1+ n-2
=> 2 = +1. Solving this, we get = (1+5)/2
=> n = n-1+ n-2. Solving this, we get = ((1+5)/2)n
15 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A
c(n)=(2n)!/(n+1)!n!
A solution (set of values for the decision variables) for which all of the constraints in
the Solver model are satisfied is called a feasible solution. In some problems, a feasible
solution is already known; in others, finding a feasible solution may be the hardest part of the
problem.
An optimal solution is a feasible solution where the objective function reaches its
maximum (or minimum) value for example, the most profit or the least cost. A globally
optimal solution is one where there are no other feasible solutions with better objective
function values. A locally optimal solution is one where there are no other feasible solutions
in the vicinity with better objective function values.
4. What is LPP?
Linear programming problem (LPP) is to optimize a linear function of several
variables subject to linear constraints:
Maximize (or minimize) c1 x1 + ...+ cn xn
Subject to ai 1x1+ ...+ ain xn (or or =) bi , i = 1,...,m
x1 0, ... , xn 0
The function z = c1 x1 + ...+ cn xn is called the objective function;
Constraints x1 0, ... , xn 0 are called nonnegativity constraints
6. Write the steps to solve LPP problems by Simplex Method / Procedure for Simplex
Method.
Step 0 [Initialization] Present a given LP problem in standard form and set up
initial tableau.
Step 1 [Optimality test] If all entries in the objective row are nonnegative then
stop: the tableau represents an optimal solution.
Step 2 [Find entering variable] Select the most negative entry in the objective
row. Mark its column to indicate the entering variable and the pivot column.
23 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A
Step 3 [Find departing (leaving) variable] For each positive entry in the pivot
column, calculate the -ratio by dividing that row's entry in the rightmost column
(solution) by its entry in the pivot column. (If there are no positive entries in the
pivot column then stop: the problem is unbounded.) Find the row with the
smallest -ratio, mark this row to indicate the departing variable and the pivot
row.
Step 4 [Form the next tableau] Divide all the entries in the pivot row by its entry
in the pivot column. Subtract from each of the other rows, including the objective
row, the new pivot row multiplied by the entry in the pivot column of the row in
question. Replace the label of the pivot row by the variable's name of the pivot
column and go back to Step 1.
14. How will you calculate new pivot row and remaining rows in new iteration of
simplex method?
Pivot row:
New Pivot Row = Current Pivot Row / Pivot Element
All other rows including z:
New Row = Current Row (Its Pivot column coefficient)* New Pivot Row
25 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A
1) Explicit constraints:
Explicit constraints are rules that restrict each Xi to take values only from a
given set. Some examples are,
Xi >0 or Si = {all non-negative real nos.}
Xi =0 or 1 or Si={0,1}.
Li Xi Ui or Si= {a: Li a Ui}
All tupules that satisfy the explicit constraint define a possible solution space.
2) Implicit constraints:
The implicit constraint determines which of the tuples in the solution space can
actually satisfy the criterion functions.
All the edges from the labeled to unlabeled vertices are full, i.e., their flow
amounts are equal to the edge capacities, while all the edges from the
unlabeled to labeled vertices, if any, have zero flow amounts on them.
Maximum flow=minimum cut
need to be asked by any algorithm in the worst case. This example illustrates the adversary
method for establishing lower bounds.
Find the most valuable subset of n items of given positive integer weights and values
that fit into a knapsack of a given positive integer capacity.
19. Define Class NP-Hard. / List out the properties of NP-Hard Problems.
32 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A
A problem is NP-hard if an algorithm for solving it can be translated into one for solving
any NP-problem (nondeterministic polynomial time) problem. Therefore NP-hard means "at
least as hard as any NP-problem," although it might, in fact, be harder.
There are no polynomial-time algorithms for NP-hard problems.
Traveling salesman and knapsack problems are NP-hard problems.
Examples:
Capacitated minimum spanning tree, Route inspection problem (also called Chinese postman
problem), Clique problem, Maximum independent set, Minimum spanning tree, Complete
coloring, Bandwidth problem, Clique cover problem, Graph homomorphism problem, Graph
coloring, Graph partition into subgraphs of specific types (triangles, isomorphic subgraphs,
Hamiltonian subgraphs, forests, perfect matchings) are known NP-complete.
28. List out coping techniques with the Limitations of Algorithm Power.
Backtracking
n-Queens Problem
Hamiltonian Circuit Problem
Subset-Sum Problem
Branch-and-Bound
Assignment Problem
Knapsack Problem
Traveling Salesman Problem
Approximation Algorithms for NP-Hard Problems
Approximation Algorithms for the Traveling Salesman Problem
Approximation Algorithms for the Knapsack Problem
Algorithms for Solving Nonlinear Equations
Bisection Method
False Position Method
Newtons Method
37. 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 are necessary.
40. What are the additional items are required for branch and bound compare to
backtracking technique?
Compared to backtracking, branch and bound requires 2 additional items.
1) A way to proved , for every node of node of state space tree, a bound on the best value of
the
objective function on any solution that can be obtain d by adding further components to the
partial solution represented by the node.
2) The value of the best solution seen so far.
50. What do you mean by accuracy ratio and performance ratio of approximation
algorithm?
where s is an exact solution to the problem. Alternatively, re(sa) = f (sa)/f (s*) 1, we can
*
The best (i.e., the smallest) value of c for which inequality holds for all instances of
the problem is called the performance ratio of the algorithm and denoted RA.
51. Differentiate promising and non promising node in a state space tree.
A node is said to be promising if the partial solution is still feasible. Any time the
partial node becomes infeasible the node, called non-promising the branch will no longer be
pursued. So, the algorithm backtracks to the first promising node and explores the other
branches of the state-space tree.
REFERENCES:
2. Thomas H.Cormen, Charles E.Leiserson, Ronald L. Rivest and Clifford Stein,
Introduction to Algorithms, Third Edition, PHI Learning Private Limited, 2012.
3. Alfred V. Aho, John E. Hopcroft and Jeffrey D. Ullman, Data Structures and
Algorithms, Pearson Education, Reprint 2006.
4. Donald E. Knuth, The Art of Computer Programming, Volumes 1& 3 Pearson
Education, 2009.
5. Steven S. Skiena, The Algorithm Design Manual, Second Edition, Springer, 2008.
6. http://nptel.ac.in/