Вы находитесь на странице: 1из 39

1 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Year & Semester : II / IV


Subject Code : CS6402
Subject Name : DESIGN AND ANALYSIS OF ALGORITHM
Degree & Branch : B.E C.S.E.

UNIT I INTRODUCTION

1. What is the necessity of studying algorithms?


From a practical standpoint, a standard set of algorithms from different areas of
computing must be known, in addition to be able to design them and analyze their
efficiencies. From a theoretical stand point the study of algorithms in the corner stone of
computer science.

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.

3. Write algorithmic problem solving steps.


Steps involved in Algorithmic Problem Solving are:
1. Understanding the problem
2. Decision making
3. Methods for specifying the algorithm
4. Proving an algorithms correctness
5. Analyzing an algorithm
6. Coding an algorithm
Algorithmic Problem Solving characteristics
1. Study of algorithms
2. It is a branch of computer science
3. Implementation of algorithms in some languages
4. Application of algorithms to a variety of problems
5. Steps to solve problem using algorithms
Algorithmic Problem Solving must have:
1. Unambiguous problem description
2. Parsing and formatting text
3. Mathematics
4. Advanced data structures
5. Algorithms and design techniques
6. code performance analysis

4. What is an algorithm? Give an example. / Write euclids algorithm


An algorithm is a sequence of unambiguous instructions for solving a problem, i.e.,
for obtaining a required output for any legitimate input in finite amount of time.
2 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

Example: ALGORITHM Euclid_gcd(m, n)


//Computes gcd(m, n) by Euclids 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
mn
nr
return m

5. Write the Characteristics of an algorithm.


Input: Zero / more quantities are externally supplied.
Output: At least one quantity is produced.
Definiteness: Each instruction is clear and unambiguous.
Finiteness: If the instructions of an algorithm is traced then for all cases the algorithm
must terminates after a finite number of steps.
Efficiency: Every instruction must be very basic and runs in short time.

6. Give the diagram representation of Notion of algorithm.

Problem to be solved

Algorithm

Input Computer Program Output

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.

8. Write Euclids algorithm for computing gcd(m, n).


ALGORITHM Euclid_gcd(m, n)
//Computes gcd(m, n) by Euclids 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
mn
nr
return m
Example: gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.

9. What are the fundamental steps involved in algorithmic problem solving?


The fundamental steps are
1. Understanding the problem
2. Decision making
a. Ascertain the capabilities of computational device
b. Choose between exact and approximate problem solving
3 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

c. Decide on appropriate data structures


d. Algorithm design techniques
3. Methods for specifying the algorithm
a. Natural language
b. Pseudocode
c. Flowchart
4. Proving an algorithms correctness
5. Analyzing an algorithm
a. Time efficiency
b. Space efficiency
6. Coding an algorithm

10. What is an algorithm design technique?


An algorithm design technique is a general approach to solving problems
algorithmically that is applicable to a variety of problems from different
areas of computing.
Algorithms+ Data Structures = Programs
Though Algorithms and Data Structures are independent, but they are
combined together to develop program. Hence the choice of proper data
structure is required before designing the algorithm.
Algorithmic strategy / technique / paradigm are a general approach by which
many problems can be solved algorithmically. E.g., Brute Force, Divide and
Conquer, Dynamic Programming, Greedy Technique, Brach & bound
and so on.

11. What is pseudo code?


A pseudo code is a mixture of a natural language and programming language
constructs to specify an algorithm. A pseudo code is more precise than a natural language
and its usage often yields more concise algorithm descriptions.
ALGORITHM Sum(a,b)
//Problem Description: This algorithm performs addition of two numbers
//Input: Two integers a and b
//Output: Addition of two integers
ca+b
return c

12. What are the types of algorithm efficiencies?


The two types of algorithm efficiencies are
Time efficiency: indicates how fast the algorithm runs
Space efficiency: indicates how much extra memory the algorithm needs

13. What is Space complexity?


Space complexity is a measure of the amount of working storage an algorithm needs.
That means how much memory, in the worst case, is needed at any point in the algorithm. As
with time complexity, we're mostly concerned with how the space needs grow, in big-Oh
terms, as the size N of the input problem grows.

14. What is time complexity?


The time complexity of an algorithm quantifies the amount of time taken by an algorithm
to run as a function of the length of the string representing the input. The time complexity of
an algorithm is commonly expressed using big O notation, which excludes coefficients and
lower order terms.
4 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

15. How will you Prove an Algorithms Correctness?


Once an algorithm has been specified then its correctness must be proved.
An algorithm must yields a required result for every legitimate input in a finite
amount of time. For example, the correctness of Euclids algorithm for computing the
greatest common divisor stems from the correctness of the equality gcd(m, n) = gcd(n,
m mod n).
A common technique for proving correctness is to use mathematical induction
because an algorithms iterations provide a natural sequence of steps needed for such
proofs.
The notion of correctness for approximation algorithms is less straightforward than it
is for exact algorithms. The error produced by the algorithm should not exceed a
predefined limit.
Better than existing algorithm by comparison method.

16. Mention some of the important problem types?


Some of the important problem types are as follows
1. Sorting
2. Searching
3. String processing
4. Graph problems
5. Combinatorial problems
6. Geometric problem
7. Numerical problems

17. What are the steps involved in the analysis framework?


The various steps for the analysis framework are as follows
1. Measuring the input's size
2. Units for measuring running time
3. Orders of growth
4. Worst case, best case and average case efficiencies

18. Write about fundamentals of the analysis of algorithm efficiency.


The efficiency of an algorithm can be in terms of time and space.
The algorithm efficiency can be analyzed by the following ways.
a. Analysis Framework.
b. Asymptotic Notations and its properties.
c. Mathematical analysis for Recursive algorithms.
d. Mathematical analysis for Non-recursive algorithms.

19. What is the basic operation of an algorithm and how is it identified?


The most important operation of the algorithm is called the basic operation of the
algorithm, the operation that contributes the most to the total running time. It can be
identified easily because it is usually the most time consuming operation in the
algorithms innermost loop. The most important operation (+, -, *, /) of the algorithm,
called the basic operation.
One possible approach is to count the number of times each of the algorithms
operations is executed. This approach is excessively difficult.
5 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

20. What is the running time of a program implementing the algorithm?


The running time T(n) is given by the following formula C(n)
Cop (n) is the time of execution of an algorithm's basic operation on a particular
computer and C(n) is the number of times this operation needs to be executed for
the particular algorithm.

21. What are exponential growth functions?


The functions 2n and n! are exponential growth functions, because these two
functions grow so fast that their values become astronomically large even for smaller
values of n.

22. What is worst-case efficiency?


The worst-case efficiency of an algorithm is its efficiency for the worst-case input of
size n, which is an input or inputs of size n for which the algorithm runs the longest
among all possible inputs of that size.

23. What is best-case efficiency?


The best-case efficiency of an algorithm is its efficiency for the best-case input of
size n, which is an input or inputs for which the algorithm runs the fastest among all
possible inputs of that size.

24. What is average case efficiency?


The average case efficiency of an algorithm is its efficiency for an average case input
of size n. It provides information about an algorithm behavior on a typical or random
input.

25. What is amortized efficiency?


In some situations a single operation can be expensive, but the total time for the entire
sequence of n such operations is always significantly better that the worst case efficiency
of that single operation multiplied by n. this is called amortized efficiency.

26. Define asymptotic notation. / List some asymptotic notations


O-notation
A function t(n) is said to be in O(g(n)), denoted by t(n) O(g(n)), if t(n) is bounded
above by some constant multiple of g(n) for all large n, i.e., if there exists some positive
constant c and some nonnegative integer n0 such that T(n) <= cg(n) for all n >= n0
notation
A function t(n) is said to be in (g(n)), denoted by t(n) (g(n)), if t(n) is bounded
below by some constant multiple of g(n) for all large n, i.e., if there exists some positive
constant c and some nonnegative integer n0 such that T(n) >= cg(n) for all n >= n0
-notation
A function t(n) is said to be in (g(n)), denoted by t(n) (g(n)), if t(n) is bounded
both above & below by some constant multiple of g(n) for all large n, i.e., if there exists
some positive constants c1 & c2 and some nonnegative integer n0 such that c2g(n) <= t(n)
<= c1g(n) for all n >= n0
6 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

27. Compare asymptotic notations

O-notation notation -notation


T(n) <= cg(n) T(n) >= cg(n) c2g(n) <= t(n) <= c1g(n)
Easy to calculate. Easy to calculate. More calculations than others.
(Tight bound)
Useful for worst case Useful for best case Useful for average case analysis.
analysis. analysis.
Bounded by upper curve. Bounded by lower curve Bounded by both upper curve
and lower curve.
Bounded by least Bounded by most Bounded by least maximum and
maximum. minimum. most minimum.

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)

30. Compare sequential search and binary search


Sequential search Binary search
This is the simple technique of searching This is the efficient technique of searching
an element. an element.
This technique does not require the list to This technique requires the list to be sorted.
be sorted. Then only this method is applicable.
Every element of the list may get Only the mid element of the list and sublist
compared with the key element. are compared with the key element.
The worst case time complexity is O(n). The worst case time complexity is O(log n).

31. Define O-notation?


A function t(n) is said to be in O(g(n)), denoted by t(n) O(g(n)), if t(n) is bounded
above by some constant multiple of g(n) for all large n, i.e., if there exists some positive
constant c and some nonnegative integer n0 such that T(n) <= cg(n) for all n >= n0
E.g., n3-5n2-7n+8 O(n3)

32. Define -notation?


A function t(n) is said to be in (g(n)), denoted by t(n) (g(n)), if t(n) is bounded
below by some constant multiple of g(n) for all large n, i.e., if there exists some positive
constant c and some nonnegative integer n0 such that T(n) >= cg(n) for all n >= n0
E.g., n3-5n2-7n+8 (n2)

33. Define -notation?


A function t(n) is said to be in (g(n)), denoted by t(n) (g(n)), if t(n) is bounded
both above & below by some constant multiple of g(n) for all large n, i.e., if there exists
some positive constants c1 & c2 and some nonnegative integer n0 such that
c2g(n) <= t(n) <= c1g(n) for all n >= n0
E.g., n3-5n2-7n+8 (n3)
7 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

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.

35. What are the basic asymptotic efficiency classes?


List the various classes of the time efficiencies of algorithms.
Constant :1 Quadratic : n2
Logarithmic : log n Cubic : n3
Linear :n Exponential : 2n
N-log-n : nlog n Factorial : n!

36. Compare the order of growth 2n and n2.


n n2 2n
Polynomial Quadratic Exponential
1 1 2
2 4 4
4 16 16
8 64 2.6102
10 102 103
16 2.610 2
6.5104
102 104 1.31030
Complexity Low High
Growth Low Very high

37. Compare the order of growth and .


n
Polynomial Logarithmic Square root
1 0 1
4 2 2
10 3.3 3.2
16 4 4
102 6.6 10
103 10 31
104 13 102
105 17 316
6
10 20 103
Complexity Low High
Growth Low High

38. Show that = + is (log n)


= + , a=1, b=2, and d=0;
By master theorem, T(n) (nd log n)
Therefore, T(n) (n0 log n)
T(n) (log n)
8 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

39. If = + + then prove that is .


= + +
<= + +
= 15
where n>=1 and c=15.

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

41. Write algorithm for linear search.


ALGORITHM Search(A[0..n - 1], K)
//Searches for a given value in a given array by sequential search
//Input: An array A[0..n - 1] and a search key K
//Output: The index of the first element in A that matches K or -1 if there are no
// matching elements
i 0
while i < n and A[i] K do
i i + 1
if i < n return i
else return -1

42. Define recursive algorithm.


A recursive algorithm is an algorithm which calls itself with "smaller (or simpler)"
input values, and which obtains the result for the current input by applying simple operations
to the returned value for the smaller (or simpler) input.
EXAMPLE : Compute the factorial function F(n) = n! for an arbitrary nonnegative integer n.
Since n!= 1. . . . (n 1) n = (n 1)! n, for n 1 and 0!= 1 by definition, we can
compute F(n) = F(n 1) n with the following recursive algorithm.

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.

45. Differentiate between recursive Algorithms and non-recursive Algorithms.


Compare and contrast between recursive Algorithms and non-recursive Algorithms.
Non-Recursive Algorithms Recursive Algorithms
Similarities
Decide on parameter n indicating Decide on parameter n indicating input size
input size
Identify algorithms basic operation Identify algorithms basic operation
Determine worst, average, and best Determine worst, average, and best case for input
case for input of size n of size n
Differences
A non-recursive technique is A recursive technique is nothing but a function
anything that doesn't use recursion. calls itself.
Set up summation for C(n) Set up a recurrence relation and initial condition(s)
reflecting algorithms loop structure for C(n)-the number of times the basic operation
will be executed for an input of size n
No recursion. So no recursive calls Count the number of recursive calls.
count
Simplify summation using standard Solve the recurrence to obtain a closed form or
formulas. estimate the order of magnitude of the solution.
E.g. Insertion sort, Matrix E.g. Fibonacci, Factorial, Merge sort, Quick sort.
multiplication, maximum element Tower of Hanoi.
in array.

46. What is called Substitution Method? Write its types.


Replacing one term with another equal term is called substitution. Forward substitution and
backward substitution are two types of substitution. It is very useful in solving recursive
algorithms.
10 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

UNIT II BRUTE FORCE AND DIVIDE-AND-CONQUER

1. Define Brute force approach?


Brute force is a straightforward approach to solving a problem, usually directly based
on the problems statement and definitions of the concepts involved. The brute force
approach is one that is easiest to apply.

2. What are the advantages of brute force technique?


The various advantages of brute force technique are:
Brute force applicable to a very wide variety of problems. It is used for many
elementary but important algorithmic tasks
For some important problems this approach yields reasonable algorithms of at least
some practical value with no limitation on instance size
The expense to design a more efficient algorithm may be unjustifiable if only a few
instances of problems need to be solved and a brute force algorithm can solve those
instances with acceptable speed
Even if inefficient in general it can still be used for solving small-size instances of a
problem
It can serve as a yardstick with which to judge more efficient alternatives for solving
a problem

3. Define Selection Sort


First scan the entire given list to find its smallest element and exchange it with the
first element, putting the smallest element in its final position in the sorted list.
Then scan the list, starting with the second element, to find the smallest among the
last n 1 elements and exchange it with the second element, putting the second
smallest element in its final position in the sorted list.
Generally, on the ith pass through the list, which we number from 0 to n 2, the
algorithm searches for the smallest item among the last n i elements and swaps
it with Ai:
A0 A1 . . . Ai1 | Ai, . . . , Amin, . . . , An1
in their final positions | the last n i elements
After n 1 passes, the list is sorted.

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

5. Define Closest-Pair Problem


The closest-pair problem finds the two closest points in a set of n points. It is the
simplest of a variety of problems in computational geometry that deals with proximity of
points in the plane or higher-dimensional spaces.
11 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

6. Define convex set and convex hull


Convex Set
A set of points (finite or infinite) in the plane is called convex if for any two points p
and q in the set, the entire line segment with the endpoints at p and q belongs to the set.
Convex hull
The convex hull of a set S of points is the smallest convex set containing S. (The
smallest convex hull of S must be a subset of any convex set containing S.)

7. What are the exhaustive search


For discrete problems in which no efficient solution method is known, it might be
necessary to test each possibility sequentially in order to determine if it is the solution.
Such exhaustive examination of all possibilities is known as exhaustive search, complete
search or direct search.Exhaustive search is simply a brute force approach to combinatorial
problems (Minimization or maximization of optimization problems and constraint satisfaction
problems).
Exhaustive Search is applied to the important problems like
Traveling Salesman Problem
Knapsack Problem
Assignment Problem

8. What is meant by traveling salesman problem?


The traveling salesman problem (TSP) is one of the combinatorial problems. The
problem asks to find the shortest tour through a given set of n cities that visits each city
exactly once before returning to the city where it started.

9. Define knapsack problem.


Given n items of known weights w1, w2, . . . , wn and values v1, v2, . . . , vn and a
knapsack of capacity W, find the most valuable subset of the items that fit into the knapsack.
Item weight value capacity
1 4 $40
2 7 $42 W = 10
3 5 $25
4 1 $10
Solution: item 1, 3, 4 values = $40+$25+$10=$75.

10. Define assignment problem.


There are n people who need to be assigned to execute n jobs, one person per job.
(That is, each person is assigned to exactly one job and each job is assigned to exactly one
person.) The cost that would accrue if the ith person is assigned to the jth job is a known
quantity [ , ] for each pair , = , , . . . , . The problem is to find an assignment with the
minimum total cost.

11. Explain divide and conquer algorithm.


What is divide and conquer strategy?

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

2. The subproblems are solved (typically recursively, though sometimes a different


algorithm is employed, especially when subproblems become small enough).
3. 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
Strassens Matrix Multiplication.

12. Write algorithm for merge sort.


Mergesort is based on divide-and-conquer technique. It sorts a given array A[0..n1] by
dividing it into two halves A[0.. / 1] and A[ / ..n1], sorting each of them
recursively, and then merging the two smaller sorted arrays into a single sorted one.

ALGORITHM Mergesort(A[0..n 1])


//Sorts array A[0..n 1] by recursive mergesort
//Input: An array A[0..n 1] of orderable elements
//Output: Array A[0..n 1] sorted in nondecreasing order
if n > 1
copy A[0.. / 1] to B[0.. / 1]
copy A[ / ..n 1] to C[0.. / 1]
Mergesort(B[0.. / 1])
Mergesort(C[0.. / 1])
Merge(B, C, A) //see below

13. Define quick sort.


Quicksort is the other important sorting algorithm that is based on the divide-and-
conquer approach. quicksort divides input elements according to their value. A partition is an
arrangement of the arrays elements so that all the elements to the left of some element A[s]
are less than or equal to A[s], and all the elements to the right of A[s] are greater than or equal
to it:

14. Differentiate quick sort and merge sort.


Sl. No. Merge sort Quick sort
1. Merge sort is a stable sort. Quick sort is not a stable sort. Pivot
element plays major role in sorting.
2. It requires extra space (Storage) for It does not require extra space (Storage)
sorting. for sorting.
3. Merge sort is a not in-place sort. Merge sort is in-place sort.
4. Used as external sorting. Used as internal sorting.
5. Best to sort big volume of data. Best for small instances of data.
6. It is Slower than quick sort. It is Better than merge sort

15. Define strassens matrix multiplication


The Strassens Matrix Multiplication find the product C of two 2 2 matrices A and B
with just seven multiplications as opposed to the eight required by the brute-force
algorithm.

where
13 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

7 multiplications and 12 additions and 6 subtractions.

16. Compare strassens algorithm and brute force algorithm for matrix multiplication.
strassens matrix multiplication algorithm

Sl. No. Strassens matrix multiplication brute force matrix multiplication


algorithm 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

UNIT III DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE

1. What is Dynamic programming?


Dynamic programming is an algorithm design technique for solving problem with
overlapping subprograms. The smaller subprograms are solved only once and recording the
results in a table from which the solution to the original problem is obtained.
Procedure;
1. Solution to the problem is carried out by results of sequence of decisions.
2. Enumerate all decision sequences and then pick out the best.
3. Optimal sequence of decision is obtained.
Example:
1. Computing Binomial coefficient
2. Knapsack Problem and Memory Functions
3. Optimal Binary Search Trees
4. Warshalls and Floyds Algorithms

2. What is greedy method? / Write a short note on greedy approach.


The greedy method is the most straight forward design, which is applied for
change making problem. The greedy technique suggests constructing a solution to an
optimization problem through a sequence of steps, each expanding a partially constructed
solution obtained so far, until a complete solution to the problem is reached. On each step, the
choice made must be feasible, locally optimal and irrevocable.
Some greedy techniques are:
1. Prims Algorithm
2. Kruskals Algorithm
3. Dijkstras Algorithm
4. Huffman Trees and Codes

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

4. List the proving methods of Greedy Technique.


Proofs for Greedy Technique are listed below:
1. The first way is one of the common ways by mathematical induction.
2. The second way to prove optimality of a greedy algorithm is to show that on each
step it does at least as well as any other algorithm could in advancing toward the
problems goal.
3. The third way is simply to show that the final result obtained by a greedy
algorithm is optimal based on the algorithms output rather than the way it
operates.

5. List the advantage of greedy algorithm.


1) Greedy algorithm produces a feasible solution.
2) Greedy method is very simple to solve a problem.
3) Greedy method provides an optimal solution directly.

6. Write an algorithm to compute Binomial Coefficient.


Write an algorithm to compute c(n,k) using dynamic program.
Algorithm Binomial(n, k)
for i 0 to n do // fill out the table row wise
for i = 0 to min(i, k) do
if j==0 or j==i then C[i, j] 1 // Initial Condition
else C[i, j] C[i-1, j-1] + C[i-1, j] // recursive relation
return C[n, k]

(a + b)n = C(n, 0)anb0 + . . . + C(n, k)an-kbk + . . . + C(n, n) a0bn

7. Define Adjacency matrix.


An Adjacency matrix A = {aij} of a directed graph is the boolean matrix that has 1 in
its ith row and jth column if and only if there is a directed edge from the ith vertex to the jth
vertex.

8. Define Transitive closure


The transitive closure of a directed graph with n vertices can be defined as the n x n
boolean matrix T = {tij }, in which the element in the ith row and the jth column is 1 if there
exists a nontrivial path (i.e., directed path of a positive length) from the ith vertex to the jth
vertex; otherwise, tij is 0.

9. Define Distance matrix


A distance matrix is a matrix (two-dimensional array) containing the distances, taken
pairwise, between the vertices of graph.

10. Define warshalls algorithm?


Warshalls algorithm is an application of dynamic rogramming technique, which is used to
find the transitive closure of a directed graph.
The transitive closure of a directed graph with n vertices can be defined as the n x n
boolean matrix T = {tij }, in which the element in the ith row (1in) and the jth
column(1jn) is 1 if there exists a nontrivial path (i.e., directed path of a positive length)
from the ith vertex to the jth vertex; otherwise, tij is 0.
16 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

11. What is the complexity of warshalls algorithm?


Warshalls algorithms time efficiency:
ALGORITHM Warshall(A[1..n, 1..n])
//ImplementsWarshalls algorithm for computing the transitive closure
//Input: The adjacency matrix A of a digraph with n vertices
//Output: The transitive closure of the digraph
R(0) A
for k1 to n do
for i 1 to n do
for j 1 to n do
R(k)[i, j ]R(k1)[i, j ] or (R(k1)[i, k] and
(k1)
R [k, j])
return R(n)
The algorithm requires 3 nested for loops of size n = n*n*n
The order of complexity = (n3).
Warshalls algorithms Space efficiency
Space for a nxn adjacency matrix = n2 locations(. i.e matrix size0
For control variables i, j, k = 3
Total space = n2 +3 = (n2 )

12. Define Floyds algorithm?


Floyds algorithm is an application, which is used to find all the pairs shortest paths
problem. Floyds algorithm is applicable to both directed and undirected weighted graph, but
they do not contain a cycle of a negative length.

13. What is the complexity of Floyds algorithm?


Floyds algorithms time efficiency:
ALGORITHM Floyd(W[1..n, 1..n])
//Implements Floyds algorithm for the all-pairs shortest-paths problem
//Input: The weight matrix W of a graph with no negative-length cycle
//Output: The distance matrix of the shortest paths lengths
D W //is not necessary if W can be overwritten
for k1 to n do
for i 1 to n do
for j 1 to n do
D[i, j ]min{D[i, j ], D[i, k]+ D[k, j]}
return D
The algorithm requires 3 nested for loops of size n = n*n*n
The order of complexity = (n3).
Floyds algorithms Space efficiency
Storage Space for a nxn weighted matrix = n2 locations(. i.e matrix size0
For control variables i, j, k = 3
Total space = n2 +3 = (n2 )

14. Differentiate Floyd and warshall.


Factors Warshall Floyd
Input Directed graph Weighted directed graph
Matrix Adjacency matrix Distance matrix
Computation Transitive closure Shortest path distance matrix
Purpose All-Pairs Path Existence All-Pairs Shortest Paths
Problem Problem
17 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

15. Differentiate prims and kruskals algorithm.

prims algorithm Kruskals algorithm


This algorithm is for obtaining minimum This algorithm is for obtaining minimum
spanning tree by selecting the adjacent spanning tree but it is not necessary to choose
vertices of already selected vertices. the adjacent vertices of already selected vertices.
Sorting of all edge weights is not required. Sorting of all edge weights is must to construct
minimum spanning tree.
The efficiency of Prims algorithm is The efficiency of Kruskals algorithm is O(|E|
O(|E| log |V |) log |E|).
Prim's algorithm is significantly faster in Kruskal performs better in typical situations
the limit when you've got a really dense (sparse graphs) because it uses simpler data
graph with many more edges than structures.
vertices.

16. Define Binary Search Trees.


Binary Search tree is a binary tree in which each internal node x stores an element such
that the element stored in the left subtree of x are less than or equal to x and elements stored
in the right subtree of x are greater than or equal to x.

17. Define Optimal Binary Search Trees.


An optimal binary search tree (BST), sometimes called a weight-balanced binary
tree, is a binary search tree which provides the smallest possible search time for a given
sequence of accesses (or probabilities of searching elements). Optimal BSTs are generally
divided into two types: static and dynamic.
In the static optimality problem, the tree cannot be modified after it has been
constructed. In the dynamic optimality problem, the tree can be modified at any time,
typically by permitting tree rotations.

18. What is Catalan number? How it is related with OBST?


The total number of binary search trees with n keys is equal to the nth Catalan
number,

c(n)=(2n)!/(n+1)!n!

19. What is the complexity of Optimal Binary Search Trees?


The algorithms space efficiency is clearly quadratic, ie, : (n3).
The time efficiency of this version of the algorithm is cubic. It is Possible to reduce the
running time of the algorithm to (n2)

20. Define Knapsack Problem by dynamic programming.


Given n items of known weights w1, . . . , wn and values v1, . . . , vn and a knapsack of
capacity W, find the most valuable subset of the items that fit into the knapsack.
Assume that all the weights and the knapsack capacity are positive integers; the item
values do not have to be integers.
0 / 1 knapsack problem means, the chosen item should be either null or whole.
To design a dynamic programming algorithm we need to find a recursive relation
from the smaller sub problems to larger problem.
18 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

21. Define Memory functions.


Dynamic programming (DP) solves problems that have a recurrence relation. Using
the recurrences directly in a recursive algorithm is a top-down technique. It has the
disadvantage that it solves common sub problem multiple times. This leads to poor
efficiency, exponential. The dynamic programming technique is bottom-up, and solving all
the sub-problems only once. It is natural to try to combine the strengths of the top-down and
bottom-up approaches. The goal is to get a method that solves only subproblems that are
necessary and does so only once. Such a method exists; it is based on using memory
functions.

22. State the uses of memory functions to solve knapsack problem


Memory function solves a given problem in top-down manner but maintains a table
used in a bottom-up DP algorithm.
It does less number of Computations.
It does computation in less time
It requires minimum storage space (less memory).

23. List out some Greedy Techniques and their uses.


Prims algorithm: To find minimum spanning tree.
Kruskal's Algorithm: To find minimum spanning tree.
Dijkstra's Algorithm: To find single source shortest path.
Huffman Trees : To minimize encode by frequency of symbols.

24. Define Directed graph.


A directed graph (or digraph) is a graph, or set of vertices connected by edges,
where the edges have a direction associated with them.

25. What is Prims algorithm?


Prims algorithm is a greedy and efficient algorithm, which is used to find the
minimum spanning tree of a weighted connected graph.

26. What is spanning tree?


A spanning tree of an undirected connected graph is its connected acyclic subgraph
(i.e., a tree) that contains all the vertices of the graph.
Let G={V,E} be an undirected connected graph. A sub graph G={V,E} of G is a
spanning tree of G, if t is a tree.

27. What is minimum spanning tree


A minimum spanning tree is its spanning tree of the smallest weight, where the
weight of a tree is defined as the sum of the weights on all its edges. The minimum spanning
tree problem is the problem of finding a minimum spanning tree for a given weighted
connected graph.

W(T1)=6 , i.e., minimum spanning tree cost is 6.


19 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

28. List the applications of minimum spanning tree?


Spanning tree are used to obtain an independent set of circuit equations for an electric
network. Another application of spanning tree arises from the property that a spanning tree is
a minimal sub graph G of G such that V(G)=V(G) and G is connected

29. What is Kruskal's Algorithm?


Kruskals algorithm is another greedy algorithm for the minimum spanning tree
problem. Kruskals algorithm constructs a minimum spanning tree by selecting edges in
increasing order of their weights provided that the inclusion does not create a cycle. Kruskals
algorithm provides a optimal solution.

30. What is Dijkstra's Algorithm? / What is the purpose of Dijkstra's Algorithm?


Dijkstras 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.
Dijkstras algorithm provides a correct solution for a graph with non negative
weights.

31. What is path compression?


1. The better efficiency can be obtained by combining either variation of quick union
with path compression.
2. Path compression makes every node encountered during the execution of a find
operation point to the trees node.

32. What is Huffman Trees?


A Huffman tree is binary tree that minimizes the weighted path length from the root
to the leaves containing a set of redefined weights. The most important application of
Huffman trees are Huffman code.

33. What is Huffman code?


A Huffman code is a optimal prefix tree variable length encoding scheme that assigns
bit strings to characters based on their frequencies in a given text.

34. Define prims algorithm.


Prims algorithm is greedy and efficient algorithm, which is used to find the minimum
spanning tree of weighted connected graph

35. How efficient is prims algorithm?


The efficiency of the prims algorithm depends on data structure chosen for the graph.
If a graph is represented by its adjacency lists and the priority queue is implemented as a min-
heap, the running time of the algorithm is O(|E| log |V |) in a connected graph.

36. Define Kruskal's algorithm.


Kruskal's algorithm is a minimum-spanning-treealgorithm where
the algorithm finds an edge of the least possible weight that connects any two trees in the
forest.It is a greedy algorithm in graph theory as it finds a minimum spanning tree for a
connected weighted graph adding increasing cost arcs at each step.
20 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

37. What is path compression?


The better efficiency can be obtained by combining either variation of quick union
with path compression. Path compression makes every node encountered during the
execution of a find operation point to the trees node.

38. Define Dijkstras Algorithm?


Dijkstras 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. Dijkstras algorithm provides a correct solution for a graph with non negative
weights.

39. Define Huffman trees?


A Huffman tree is binary tree that minimizes the weighted path length from the root
to the leaves containing a set of predefined weights. The most important application of
Huffman trees are Huffman code.

40. Write short note on degree of tree.


The number of subtrees of a node is called the degree of the node. In a binary tree, all
nodes have degree 0, 1, or 2.
A node of degree zero is called a terminal node or leaf node.
A non-leaf node is often called a branch node.
The degree of a tree is the maximum degree of a node in the tree. A binary tree is
degree 2.
41. Write short note on path and height of tree.
A directed path from node n1 to nk is defined as a sequence of nodes n1, n2, ..., nk such
that ni is the parent of ni+1 for 1 <= i < k. An undirected path is a similar sequence of
undirected edges. The length of this path is the number of edges on the path, namely k
1 (i.e., the number of nodes 1). There is a path of length zero from every node to
itself. Notice that in a binary tree there is exactly one path from the root to each node.
The level or depth of a node with respect to a tree is defined recursively: the level of the
root is zero; and the level of any other node is one higher than that of its parent. Or to
put it another way, the level or depth of a node ni is the length of the unique path from
the root to ni.
The height of ni is the length of the longest path from ni to a leaf. Thus all leaves in the
tree are at height 0.
The height of a tree is equal to the height of the root. The depth of a tree is equal to the
level or depth of the deepest leaf; this is always equal to the height of the tree.
If there is a directed path from n1 to n2, then n1 is an ancestor of n2 and n2 is a
descendant of n1.
42. What do you mean by Huffman code?
A Huffman code is a optimal prefix tree variable length encoding scheme that assigns bit
strings to characters based on their frequencies in a given text.

43. What is meant by compression ratio in Huffman code?


Huffmans code achieves the compression ratio, which is a standard measure of
compression algorithms effectiveness of
(3-2.25)/3*100 = 0.75/3*100 .
= 0.25 *100
= 25%.
21 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

44. List the advantage of Huffmans encoding?


Huffmans encoding is one of the most important file compression methods.
Huffmans encoding is one of the most important file compression methods.
It is simple
It is versatility
It provides optimal and minimum length encoding

45. What is dynamic Huffman coding / encoding?


In dynamic Huffman coding, the coding tree is updated each time a new character is
read from the source text. Dynamic Huffman n codings used to overcome the drawback of
simplest version.

46. What is articulation point?


A vertex of a connected graph G is said to be in articulation point, if its removal with
all
edges incident to it breaks the graph into disjoint pieces.

47. What is a Biconnected Graph?


A biconnected graph is a connected graph on two or more vertices having no
articulation vertices. Such graphs are also sometimes called blocks or non-separable graphs.
A biconnected undirected graph is a connected graph that is not broken into
disconnected pieces by deleting any single vertex (and its incident edges). A biconnected
directed graph is one such that for any two vertices v and w there are two directed paths from
v to w which have no vertices in common other than v and w.

48. Tabulate the complexity of graph algorithms.

Algorithm Time complexity Space complexity


Warshalls Algorithm (n3) (n2)
Floyds Algorithm (n3) (n2)
Optimal Binary Search Trees (n3) (n2) (n2)
knapsack problem (n-items, W-weight) O(nW). O(nW).
Prims Algorithm O(|E| log |V |) (n2)
Kruskals Algorithm O(|E| log |E|). (n2)
Dijkstras Algorithm O(|E| log |V |). (|V |2)
Huffman tree code Algorithm O(n log n) O(n)
22 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

UNIT IV ITERATIVE IMPROVEMENT

1. What do you mean by optimal solution?


Given a problem with n inputs, we obtain a subset that satisfies come constraints. Any
subset that satisfies these constraints is called a feasible solution.
A feasible solution, which either maximizes or minimizes a given objective function is called
optimal solution.

2. What is feasible solution?


It is obtained from given n inputs Subsets that satisfies some constraints are called
feasible solution. It is obtained based on some constraints

3. Compare feasible and optimal solution.

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

5. What is Simplex Method?


The classic method for solving Linear programming problem (LPP.
One of the most important algorithms ever invented to solve LPP.
Invented by George Dantzig in 1947.
Based on the iterative improvement idea.
Generates a sequence of adjacent points of the problems feasible region with
improving values of the objective function until no further improvement is
possible.

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.

7. Write the time complexity of the Simplex Method.


Finding an initial basic feasible solution may pose a problem.
Theoretical possibility of cycling.
Typical number of iterations is between m and 3m, where m is
the number of equality constraints in the standard form.
Worse-case efficiency is exponential.
More recent interior-point algorithms such as Karmarkars algorithm (1984) have
polynomial worst-case efficiency and have performed competitively with the simplex
method in empirical tests.

8. Write the Standard form of LP problem.


Must be a maximization problem
All constraints (except the nonnegativity constraints) must be in the form of linear
equations
All the variables must be required to be nonnegative
Thus, the general linear programming problem in standard form with m
constraints and n unknowns (n m) is
Maximize c1 x1 + ...+ cn xn
Subject to ai 1x1+ ...+ ain xn = bi , i = 1,...,m, x1 0, ... , xn
0

9. Formulate the LPP for the given data.


A farmer has a 320 acre farm on which she plants two crops: corn and soybeans. For
each acre of corn planted, her expenses are $50 and for each acre of soybeans planted, her
expenses are $100. Each acre of corn requires 100 bushels of storage and yields a profit of
$60; each acre of soybeans requires 40 bushels of storage and yields a profit of $90. If the
total amount of storage space available is 19,200 bushels and the farmer has only $20,000 on
hand.
Linear Programming Problem Formulation
Corn Soybean Total
Expenses $50 $100 $20,000
Storage(bushels) 100 40 19,200
Profit 60 90 Maximize
profit
A farmer has a 320 acre farm is unwanted data but c+s<=320.
Canonical form of LPP
Maximize: 60c + 90s
Subject to 50c + 100s = 20000
100c + 40s = 19200
c 0, s 0
24 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

10. What are the possible outcomes in solving an LP problem?


has a finite optimal solution, which may not be unique
unbounded: the objective function of maximization (minimization) LP problem is
unbounded from above (below) on its feasible region
infeasible: there are no points satisfying all the constraints, i.e. the constraints are
contradictory

11. Solve the LPP by algebraic geometry technique.


Maximize: 60c + 90s
Subject to 50c + 100s = 20000 (1)
100c + 40s = 19200 (2)
(1)/50 => c + 2s = 400
(2)/20 => 5c + 2s = 960
(2) (1) => 4c = 560
c = 140
Substitute c = 140 in (1) then s = 130
Profit: p = 60c + 90s = 60(140) + 90(130) = 20,100

12. Solve the LPP by Graphical method.

Profit at (0, 200) = 60c + 90s = 60(0) +90(200) = $18,000


Profit at (192, 0) = 60c + 90s = 60(192) +90(0) = $11,520
Profit at (140, 130) = 60c + 90s = 60(140) +90(130) = $20,100

13. How can you convert Primal to Dual of LPP?


Primal Maximize = = ,
subject to: = i = , ,...,m ,
= , ,...,n .
Dual Minimize = = ,
subject to: = = , ,...,n ,
i = , ,...,m .

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

15. Convert the given primal problem into dual problem.


The Primal problem
Minimize 4x1 + 2x2 x3
subject to x1 + x2 + 2x3 3
2x1 2x2 + 4x3 5
x1, x2, x3 0.
The dual problem
Maximize 3y1 + 5y2
subject to y1 + 2y2 4
y1 2y2 2
2y1 + 4y2 1
y1 0, y2 0

16. Compare Explicit and Implicit Constraints.

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.

17. Define weighted graph.


A weighted graph is a graph in which a number (the weight) is assigned to each edge.
such weights might represent for example costs, lengths or capacities, depending on the
problem at hand. Some authors call such a graph a network.

18. Define multistage graph.


A multistage graph is a graph
o G=(V,E) with V partitioned into K >= 2 disjoint subsets such that if (a,b) is in E,
then a is in Vi , and b is in Vi+1 for some subsets in the partition;
o and | V1 | = | VK | = 1.
The vertex s in V1 is called the source; the vertex t in VK is called the sink.
G is usually assumed to be a weighted graph.
The cost of a path from node v to node w is sum of the costs of edges in the path.
The "multistage graph problem" is to find the minimum cost path from s to t.
26 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

19. Define source and sink node of graph.


A Flow graph contains 1 source node and 1 sink node.
Source node: Unique vertex with no entering edges.
Sink node: Unique vertex with no leaving edges.

20. What is Maximum Flow Problem?


Problem of maximizing the flow of a material through a transportation network (e.g.,
pipeline system, communications or transportation networks)
Formally represented by a connected weighted digraph with n vertices numbered from 1
to n with the following properties:
contains exactly one vertex with no entering edges, called the source (numbered 1)
contains exactly one vertex with no leaving edges, called the sink (numbered n)
has positive integer weight uij on each directed edge (i.j), called the edge capacity,
indicating the upper bound on the amount of the material that can be sent from i to j
through this edge.
A digraph satisfying these properties is called a flow network or simply a network.

21. Define Flow


A flow is an assignment of real numbers xij to edges (i,j) of a given network that
satisfy the following:
flow-conservation requirements
The total amount of material entering an intermediate vertex must be equal to the
total amount of the material leaving the vertex
capacity constraints
0 xij uij for every edge (i,j) E

22. What is Flow value and Maximum Flow Problem


Since no material can be lost or added to by going through intermediate vertices of the
network, the total amount of the material leaving the source must end up at the sink:
x1j = xjn
j: (1,j) E j: (j,n) E
The value of the flow is defined as the total outflow from the source (= the total
inflow into the sink). The maximum flow problem is to find a flow of the largest value
(maximum flow) for a given network.

23. Write the Maximum-Flow Problem as LP problem.


Maximize v = x1j
j: (1,j) E
subject to
xji - xij = 0 for i = 2, 3,,n-1
j: (j,i) E j: (i,j) E
0 xij uij for every edge (i,j) E
27 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

24. Explain Augmenting Path (Ford-Fulkerson) Method


Start with the zero flow (xij = 0 for every edge).
On each iteration, try to find a flow-augmenting path from source to sink, which a
path along which some additional flow can be sent.
If a flow-augmenting path is found, adjust the flow along the edges of this path to
get a flow of increased value and try again.
If no flow-augmenting path is found, the current flow is maximum.

25. Write Shortest-Augmenting-Path Algorithm


Generate augmenting path with the least number of edges by BFS as follows.
Starting at the source, perform BFS traversal by marking new (unlabeled) vertices with two
labels:
first label indicates the amount of additional flow that can be brought from the
source to the vertex being labeled
second label indicates the vertex from which the vertex being labeled was
reached, with + or added to the second label to indicate whether the vertex
was reached via a forward or backward edge.

26. Write about Vertex labeling


The source is always labeled with ,-
All other vertices are labeled as follows:
o If unlabeled vertex j is connected to the front vertex i of the traversal queue by
a directed edge from i to j with positive unused capacity rij = uij xij (forward
edge), vertex j is labeled with lj,i+, where lj = min{li, rij}
o If unlabeled vertex j is connected to the front vertex i of the traversal queue by
a directed edge from j to i with positive flow xji (backward edge), vertex j is
labeled lj,i-, where lj = min{li, xji}
If the sink ends up being labeled, the current flow can be augmented by the amount
indicated by the sinks first label.
The augmentation of the current flow is performed along the augmenting path traced
by following the vertex second labels from sink to source; the current flow quantities
are increased on the forward edges and decreased on the backward edges of this path.
If the sink remains unlabeled after the traversal queue becomes empty, the algorithm
returns the current flow as maximum and stops.

27. Define Cut


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.
Well denote a cut and its capacity by C(X,X) and c(X,X)
Note that if all the edges of a cut were deleted from the network, there would be
no directed path from source to sink
Minimum cut is a cut of the smallest capacity in a given network

28. Write Max-Flow Min-Cut Theorem


1. The value of maximum flow in a network is equal to the capacity of its minimum cut
2. The shortest augmenting path algorithm yields both a maximum flow and a minimum cut:
Maximum flow is the final flow produced by the algorithm
Minimum cut is formed by all the edges from the labeled vertices to unlabeled
vertices on the last iteration of the algorithm.
28 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

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

29. Define Bipartite Graphs


Bipartite graph: a graph whose vertices can be partitioned into two disjoint sets V and
U, not necessarily of the same size, so that every edge connects a vertex in V to a vertex in U.
A graph is bipartite if and only if it does not have a cycle of an odd length.

30. Define Matching in a Graph


A matching in a graph is a subset of its edges with the property that no two edges share a
vertex

a matching in this graph M = {(4,8), (5,9)}

31. Define maximum matching or maximum cardinality


A maximum (or maximum cardinality) matching is a matching with the largest
number of edges
always exists
not always unique

32. Define Stable Marriage Problem


There is a set Y = {m1,,mn} of n men and a set X = {w1,,wn} of n women. Each
man has a ranking list of the women, and each woman has a ranking list of the men
(with no ties in these lists).
A marriage matching M is a set of n pairs (mi, wj).
A pair (m, w) is said to be a blocking pair for matching M if man m and woman w are
not matched in M but prefer each other to their mates in M.
A marriage matching M is called stable if there is no blocking pair for it; otherwise,
its called unstable.
The stable marriage problem is to find a stable marriage matching for mens and
womens given preferences.

33. Analyze the Gale-Shapley Algorithm


The algorithm terminates after no more than n2 iterations with a stable marriage
output.
The stable matching produced by the algorithm is always man-optimal: each man gets
the highest rank woman on his list under any stable marriage. One can obtain the
woman-optimal matching by making women propose to men.
A man (woman) optimal matching is unique for a given set of participant preferences.
The stable marriage problem has practical applications such as matching medical-
school graduates with hospitals for residency training.
29 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

UNIT V COPING WITH THE LIMITATIONS OF ALGORITHM POWER

1. What are the limitations of algorithm power?


There are many algorithms for solving a variety of different problems. They are very
powerful instruments, especially when they are executed by modern computers.
The power of algorithms is because of the following reasons:
There are some problems cannot be solved by any algorithm.
There are some problems can be solved algorithmically but not in polynomial
time.
There are some problems can be solved in polynomial time by some algorithms,
but there are usually lower bounds on their efficiency.
Algorithms limits are identified by the following:
Lower-Bound Arguments
Decision Trees
P, NP and NP-Complete Problems

2. What are lower-bound arguments?


We can look at the efficiency of an algorithm two ways. We can establish its
asymptotic efficiency class (say, for the worst case) and see where this class stands with
respect to the hierarchy of efficiency classes.
Lower bounds means estimating the minimum amount of work needed to solve the
problem. We present several methods for establishing lower bounds and illustrate them with
specific examples.
1. Trivial Lower Bounds
2. Information-Theoretic Arguments
3. Adversary Arguments
4. Problem Reduction
In analyzing the efficiency of specific algorithms in the preceding, we should
distinguish between a lower-bound class and a minimum number of times a particular
operation needs to be executed.

3. Define Trivial Lower Bounds.


The simplest method of obtaining a lower-bound class is based on counting the
number of items in the problems input that must be processed and the number of output
items that need to be produced. Since any algorithm must at least read all the items it
needs to process and write all its outputs, such a count yields a trivial lower bound.

4. Define Information-Theoretic Arguments.


The information-theoretical approach seeks to establish a lower bound based on the
amount of information it has to produce by algorithm.

5. Define Adversary Arguments.


Adversary Argument is a method of proving by playing a role of adversary in which
algorithm has to work more for adjusting input consistently.
Consider the Game of guessing number between positive integer 1 and n by asking a
person (Adversary) with yes/no type answers for questions. After each question at least one-
half of the numbers reduced. If an algorithm stops before the size of the set is reduced to 1,
the adversary can exhibit a number.
Any algorithm needs log2 n iterations to shrink an n-element set to a one-element set
by halving and rounding up the size of the remaining set. Hence, at least log2 n questions
30 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

need to be asked by any algorithm in the worst case. This example illustrates the adversary
method for establishing lower bounds.

6. Define Problem Reduction.


Problem reduction is a method in which a difficult unsolvable problem P is reduced to
another solvable problem B which can be solved by a known algorithm.
A similar reduction idea can be used for finding a lower bound. To show that problem
P is at least as hard as another problem Q with a known lower bound, we need to reduce Q to
P (not P to Q!). In other words, we should show that an arbitrary instance of problem Q can
be transformed to an instance of problem P, so any algorithm solving P would solve Q as
well. Then a lower bound for Q will be a lower bound for P.

7. Define decision trees.


Important algorithms like sorting and searching are based on comparing items of their
inputs. The study of the performance of such algorithm is called a decision tree. As an
example, Figure presents a decision tree of an algorithm for finding a minimum of three
numbers. Each internal node of a binary decision tree represents a key comparison indicated
in the node.

Decision tree for finding a minimum of three numbers.

8. Define tractable and intractable.


Problems that can be solved in polynomial time are called tractable, and problems
that cannot be solved in polynomial time are called intractable.

9. Define Hamiltonian circuit problem.


Determine whether a given graph has a Hamiltonian circuita path that starts and
ends at the same vertex and passes through all the other vertices exactly once.

10. Define Traveling salesman problem.


Find the shortest tour through n cities with known positive integer distances between
them (find the shortest Hamiltonian circuit in a complete graph with positive integer
weights).
Applications
Vehicle routing.
Discrete optimization
Computer network problem
Airport tour.
Sonnet ring
Power cable

11. Define Knapsack problem.


31 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

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.

12. Define Partition problem.


Given n positive integers, determine whether it is possible to partition them into two
disjoint subsets with the same sum.

13. Define Bin-packing problem.


Given n items whose sizes are positive rational numbers not larger than 1, put them
into the smallest number of bins of size 1.

14. Define Graph-coloring problem.


For a given graph, find its chromatic number, which is the smallest number of colors
that need to be assigned to the graphs vertices so that no two adjacent vertices are assigned
the same color. Every Planner graph is 4 colorable.

15. Define Integer linear programming problem.


Find the maximum (or minimum) value of a linear function of several integer-valued
variables subject to a finite set of constraints in the form of linear equalities and inequalities.

16. Define deterministic and nondeterministic algorithm.


A nondeterministic algorithm is a two-stage procedure that takes as its input an instance I
of a decision problem and does the following.
1. Nondeterministic (guessing) stage: An arbitrary string S is generated that can be
thought of as a candidate solution to the given instance.
2. Deterministic (verification) stage: A deterministic algorithm takes both I and S as
its input and outputs yes if S represents a solution to instance I. (If S is not a solution
to instance I , the algorithm either returns no or is allowed not to halt at all.)
Finally, a nondeterministic algorithm is said to be nondeterministic polynomial if the time
efficiency of its verification stage is polynomial.

17. Define Class P.


Class P is a class of decision problems that can be solved in polynomial time by
deterministic algorithms. This class of problems is called polynomial class.
Examples:
Searching
Element uniqueness
Graph connectivity
Graph acyclicity
Primality testing

18. Define Class NP.


Class NP is the class of decision problems that can be solved by nondeterministic
polynomial algorithms. This class of problems is called nondeterministic polynomial.
Examples: Integer factorization problem, graph isomorphism problem,
All NP-complete problem (travelling salesman problem, Boolean satisfiability
problem).

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.

20. Define NP-complete.


A decision problem D is said to be NP-complete if it is hard as any problem in NP.
1. It belongs to class NP
2. Every problem in NP is polynomially reducible to D

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.

21. Compare class P and NP problems.


Class P Class NP
Class P is a class of decision problems that Class NP is the class of decision problems
can be solved in polynomial time by that can be solved by nondeterministic
deterministic algorithms. polynomial algorithms.
This class of problems is called polynomial This class of problems is called
class. nondeterministic polynomial class.
Subset of Class NP Super set of Class P
Examples: Examples:
Searching Travelling salesman problem
Element uniqueness Boolean satisfiability problem
Graph connectivity Knapsack problem
Graph acyclicity
Primality testing

22. Compare class NP hard and NP complete problems.


Class NP Hard Class NP Complete
Class of problems hard to solve. A decision problem D is said to be NP-complete if
it is hard as any problem in NP.
1. It belongs to class NP
2. Every problem in NP is polynomially
reducible to D
We can not solve all Class NP We can solve all Class NP Complete problems in
Complete problems in polynomial polynomial time
time
Super set of Class NP Complete Subset of Class NP hard
Examples: Examples:
Travelling Sales Person Travelling Sales Person
Halting problem 3- SAT problem
SAT problem
33 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

23. Compare class Deterministic and non deterministic algorithms.

A deterministic algorithm is an algorithm which, given a particular input, will always


produce the same output, with the underlying machine always passing through the same
sequence of states.
A nondeterministic algorithm is a two-stage procedure that takes as its input an instance I
of a decision problem and does the following.
1. Nondeterministic (guessing) stage: An arbitrary string S is generated that can be
thought of as a candidate solution to the given instance.
2. Deterministic (verification) stage: A deterministic algorithm takes both I and S as
its input and outputs yes if S represents a solution to instance I. (If S is not a solution
to instance I , the algorithm either returns no or is allowed not to halt at all.)
Finally, a nondeterministic algorithm is said to be nondeterministic polynomial if the time
efficiency of its verification stage is polynomial.

24. Define Cook's theorem.


In computational complexity theory, the CookLevin theorem, also known as Cook's
theorem, states that the Boolean satisfiability problem is NP-complete. That is, any problem
in NP can be reduced in polynomial time by a deterministic algorithm (Turing machine) to
the problem of determining whether a Boolean formula is satisfiable. E.g SAT-3 problem.

25. Define backtracking.


Backtracking is a general algorithmic technique that considers searching every possible
combination in order to solve an optimization problem. Backtracking is also known as depth-
first search or branch and bound. By inserting more knowledge of the problem, the search
tree can be pruned to avoid considering cases that don't look promising. While backtracking
is useful for hard problems to which we do not know more efficient solutions.
Backtracking is a general algorithm for finding all (or some) solutions to some
computational problems, notably constraint satisfaction problems, that incrementally builds
candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it
determines that c cannot possibly be completed to a valid solution.
Backtracking examples.
n-Queens Problem
Hamiltonian Circuit Problem
Subset-Sum Problem

26. Define Branch and bound.


Branch and bound (BB or B&B) is an algorithm design paradigm for discrete and
combinatorial optimization problems, as well as general real valued problems. A branch-and-
bound algorithm consists of a systematic enumeration of candidate solutions by means of
state space search: the set of candidate solutions is thought of as forming a rooted tree with
the full set at the root. The algorithm explores branches of this tree, which represent subsets
of the solution set. Before enumerating the candidate solutions of a branch, the branch is
checked against upper and lower estimated bounds on the optimal solution, and is discarded
if it cannot produce a better solution than the best one found so far by the algorithm.
The algorithm depends on the efficient estimation of the lower and upper bounds of a
region/branch of the search space and approaches exhaustive enumeration as the size (n-
dimensional volume) of the region tends to zero.
Branch-and-Bound Examples:
Assignment Problem
Knapsack Problem
Traveling Salesman Problem
34 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

27. List out Exact Solution technique.


Exhaustive search (brute force)-
useful only for small instances
Dynamic programming
applicable to some problems (e.g., the knapsack problem)
Backtracking
eliminates some unnecessary cases from consideration
yields solutions in reasonable time for many instances but worst case is
still exponential
Branch-and-bound
further refines the backtracking idea for optimization problems

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

29. Define Backtracking


Backtracking is a more intelligent variation approach.
The principal idea is to construct solutions one component at a time and evaluate
such partially constructed candidates as follows.
If a partially constructed solution can be developed further without violating the
problems constraints, it is done by taking the first remaining legitimate option for
the next component.
If there is no legitimate option for the next component, no alternatives for any
remaining component need to be considered. In this case, the algorithm backtracks
to replace the last component of the partially constructed solution with its next
option.
It is convenient to implement this kind of processing by constructing a tree of
choices being made, called the state-space tree.
Depth first node generation with bounding function is called backtracking. The
backtracking algorithm has its virtue the ability to yield the answer with far fewer
than m trials
Backtracking techniques are applied to solve the following problems
n-Queens Problem
Hamiltonian Circuit Problem
Subset-Sum Problem
35 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

30. Define N-Queens Problem.


The problem is to place n queens on an n n chessboard so that no two queens attack
each other by being in the same row or in the same column or on the same diagonal.

31. Find a solution 8 queens problem.


There is solution to place 8 queens in 8 8 chessboard.
1 2 3 4 5 6 7 8
1 Q
2 Q
3 Q
4 Q
5 Q
6 Q
7 Q
8 Q

32. Define Hamiltonian circuit problem.


A Hamiltonian circuit (also called a Hamiltonian cycle, Hamilton cycle,
or Hamilton circuit) is a graph cycle (i.e., closed loop) through a graph that visits each node
exactly once. A graph possessing a Hamiltonian cycle is said to be a Hamiltonian graph.

33. Given an application for knapsack problem?


The knapsack problem is problem combinatorial optimization. It derives its name from
the maximum problem of choosing possible essential that can fit too bag to be carried on trip.
A similar problem very often appears business, combinatory, complexity theory,
cryptography and applied mathematics.

34. Define subset sum problem.


Subset sum problem is problem, which is used to find a subset of a given set
S={S1,S2,S3,.Sn} of positive integers whose sum is equal to given positive integer d.
The subset-sum problem finds a subset of a given set A = {a1, . . . , an} of n positive
integers whose sum is equal to a given positive integer d. For example, for A = {1, 2, 5, 6, 8}
and d = 9, there are two solutions: {1, 2, 6} and {1, 8}. Of course, some instances of this
problem may have no solutions.

35. What is heuristic?


A heuristic is common sense rule drawn from experience rather than from mathematically
proved assertion. For example, going to the nearest unvisited city in the travelling salesman
problem is good example for heuristic.

36. State the concept of branch and bound method?


The branch and bound method refers to all state space search methods in which all children of
the E-Node are generated before any other live node can become the E-node.
36 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

Some problems can be solved by Branch-and-Bound are:


1. Assignment Problem
2. Knapsack Problem
3. Traveling Salesman Problem

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.

38. What is state space tree?


Backtracking and branch bound are based on the construction of a state space tree, whose
nodes reflect specific choices made for a solutions component .Its root represents an initial
state before the search for a solution begins. The nodes of the first level the tree represent the
made for the first component of solution, the nodes of the second evel represent the Choices
for the second components & so on

39. What is promising and non promising node?


A node state space tree is said to be promising, if it corresponds to a partially constructed
solution that may still lead to complete solution. Otherwise, node is called non- promising.

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.

41. Differentiate backtracking and branch bound techniques.


Backtracking is applicable only to non optimization problems.
Backtracking generates state space tree depth first manner.
Branch and bound is applicable only to optimization problem.
Branch and bound generated a node of state space tree using best first rule.

42. What is called all pair shortest path problem?


Given a weighted connected graph, the all pairs shortest paths problem is to find the distances
from each vertex to all other vertices.

43. When do you say a tree as minimum spanning tree?


A spanning tree is said to be minimum spanning tree when the weight of the spanning tree is
smallest, where the weight of a tree is defined as the sum of the weight of all its edges.

44. How will you construct an optimal binary search tree?


A binary search tree is one of the most important data structures in computer sciences. Its
principal applications are to implement a dictionary, a set of elements with the operations of
searching, insertion and deletion. If probabilities of searching for elements of a set are known
as optimal binary search tree, for which the average number of comparisons in a sear h is the
smallest possible.
37 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

45. What is the runtime of shortest path algorithm?


The runtime of shortest path algorithm is ((n+|E|) log n)

46. Define Nearest-Neighbor Algorithm


The following well-known greedy algorithm is based on the nearest-neighbor
heuristic: always go next to the nearest unvisited city.
Step 1 Choose an arbitrary city as the start.
Step 2 Repeat the following operation until all the cities have been visited: go to the
unvisited city nearest the one visited last (ties can be broken arbitrarily).
Step 3 Return to the starting city.

47. Define Knapsack Problem (Approximation Algorithm)


The knapsack problem is one well-known NP-hard problem. Given n items of known
weights w1, . . . , wn and values v1, . . . , vn and a knapsack of weight capacity W, find the most
valuable subset of the items that fits into the knapsack.

48. Define Greedy algorithm for the discrete knapsack problem


Step 1 Compute the value-to-weight ratios ri = vi/wi, i = 1, . . . , n, for the items given.
Step 2 Sort the items in nonincreasing order of the ratios computed in Step 1.(Ties
can be broken arbitrarily.)
Step 3 Repeat the following operation until no item is left in the sorted list: if the
current item on the list fits into the knapsack, place it in the knapsack and
proceed to the next item; otherwise, just proceed to the next item.

49. Define Greedy Algorithm For The Continuous Knapsack Problem


Step 1 Compute the value-to-weight ratios vi/wi, i = 1, . . . , n, for the items given.
Step 2 Sort the items in nonincreasing order of the ratios computed in Step 1. (Ties
can be broken arbitrarily.)
Step 3 Repeat the following operation until the knapsack is filled to its full capacity
or no item is left in the sorted list: if the current item on the list fits into the
knapsack in its entirety, take it and proceed to the next item; otherwise, take its
largest fraction to fill the knapsack to its full capacity and stop.

50. What do you mean by accuracy ratio and performance ratio of approximation
algorithm?

We can quantify the accuracy of an approximate solution sa to a problem of


minimizing some function f by the size of the relative error (re) of this approximation,


=

where s is an exact solution to the problem. Alternatively, re(sa) = f (sa)/f (s*) 1, we can
*

simply use the accuracy ratio



=
as a measure of accuracy of sa. Note that for the sake of scale uniformity, the accuracy ratio
of approximate solutions to maximization problems is usually computed as

=

to make this ratio greater than or equal to 1, as it is for minimization problems.
38 CS6402 DESIGN AND ANALYSIS OF ALGORITHM 2 mark Q&A

A polynomial-time approximation algorithm is said to be a c approximation


algorithm, where c 1, if the accuracy ratio of the approximation it produces does not
exceed c for any instance of the problem in question: r(sa) c.

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.

52. What is a Live Node and a Dead Node?


In a state space tree:
Live node: A node which has been generated and all of whose children
are not yet been generated.
E-Node: The live node whose children are currently being generated
(Expanded).
Dead node: A node that is either not to be expanded further, or for
which all of its children have been generated.

53. Compare backtracking and branch and bound.

Backtracking Branch and bound


It is used to find all possible solutions It is used to solve optimization problem
available to the problem.
It traverse tree by DFS(Depth First Search). It may traverse the tree in any manner, DFS
or BFS.
It realizes that it has made a bad choice & It realizes that it already has a better optimal
undoes the last choice by backing up. solution that the pre-solution leads to so it
abandons that pre-solution.
It search the state space tree until it found a It completely searches the state space tree to
solution. get optimal solution
It involves feasibility function. It involves bounding function.
Examples Examples
Puzzles such as eight queens puzzle, 0/1 knapsack problem
crosswords, verbal arithmetic, Sudoku. Travelling salesman problem
Combinatorial optimization problems (TSP)[3][10]
such as parsing and the knapsack Quadratic assignment problem (QAP)
problem. Maximum satisfiability problem (MAX-
Constraint satisfaction problem: SAT)

All the Best No substitution for hard work.


TEXT BOOK:
1. Anany Levitin, Introduction to the Design and Analysis of Algorithms, Third Edition,
Pearson Education, 2012.

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/

Вам также может понравиться