Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
61 views28 pages

DAA Unit-4 Course Material

Uploaded by

Priya Kolaparthy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views28 pages

DAA Unit-4 Course Material

Uploaded by

Priya Kolaparthy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

SVCE KADAPA

COURSE
MATERIAL
DESIGN AND ANALYSIS
SUBJECT OFALGORITHMS
(15A05604)

UNIT 4

COURSE B.TECH

DEPARTMENT COMPUTER SCIENCE AND


ENGINEERING

SEMESTER 3-2

PREPARED BY M Ravi Prasad


(Faculty Name/s) Sr.Assistant Professor

Version V-1

PREPARED / REVISED DATE 05-04-2021


SVCE KADAPA

TABLE OF CONTENTS –
UNIT 4
S. NO CONTENT PAGE NO.
S
1 COURSE OBJECTIVES 1
2 PREREQUISITES 1
3 SYLLABUS 1
4 COURSE OUTCOMES 1
5 CO - PO/PSO MAPPING 1
6 LESSON PLAN 2
7 ACTIVITY BASED LEARNING 2
8 LECTURE NOTES 2
1.1 INTRODUCTION- BRANCH AND BOUND: THE METHOD 2
1.2 0/1 KNAPSACK PROBLEM 13
1.3 TRAVELLING SALESPERSON PROBLEM 15
1.4 LOWER BOUND THEORY: COMPARISON TREES 16
1.6 LOWER BOUNDS THROUGH REDUCTIONS 16
1.7 MULTIPLYING TRIANGULAR MATRICES 18
1.8 INVERTING A LOWER TRIANGULAR MATRIX 19
1.9 COMPUTING THE TRANSITIVE CLOSURE 20
9 PRACTICE QUIZ 22
10 ASSIGNMENTS 23
11 PART A QUESTIONS & ANSWERS (2 MARKS QUESTIONS) 23
12 PART B QUESTIONS 24
13 CONTENTS BEYOND THE SYLLABUS 24
14 PRESCRIBED TEXT BOOKS & REFERENCE BOOKS 25
SVCE KADAPA

1. Course Objectives
The objectives of this course is to
1. To demonstrate the importance of algorithms in computing.
2. To explain the analysis of algorithms
3. To illustrate the method of finding the complexity of algorithms
4. To explain the advanced algorithm design and analysis techniques.
5. To introduce special classes of algorithms NP – completeness and the classes P and NP
2. Prerequisites
Students should have knowledge on
1. Analysis of Algorithmconcepts
2. Discrete mathematics
3. Probability and Statistics

4. Syllabus
UNIT IV
Branchand Bound: The method, Travelling salesperson, 0/1 Knapsack problem,
Efficiency considerations.
Lower Bound Theory: Comparison trees, Lower bounds through reductions –
Multiplying triangular matrices, inverting a lower triangular matrix, Computing
the transitive closure.

5. Course outcomes
1. Apply the knowledge of algorithms of branch and bound design technique.
2. Identify time complexity of 0/1 knapsack problem and travelling sales person problem
3. Illustrate various lower bound theory reductions problems
4. Evaluate multiplying and inverting triangular matrices.
5. Explain reduction source problems.

6. Co-PO / PSO Mapping


DAA PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 P10 PO11 PO12 PSO1 PSO2

CO1 3 3 2 2

CO2 3 3 2 2

CO3 3 3 2 2

CO4 3 3 2 2

CO5 3 3 2 2

1|D A A - U N I T - IV
SVCE KADAPA

7. Lesson Plan
Lecture No. Weeks Topics to be covered References

1 BRANCH AND BOUND: INTRODUCTION T1


2 1 The general method T1, R1
3 Travelling salesperson T1, R1
4 0/1 Knapsack problem T1, R1
5 Efficiency considerations. T1, R2

2
7 Lower Bound Theory: Comparison trees T1, R1
8 Lower bounds through reductions – Multiplying triangular T1, R1
matrices
9
3 inverting a lower triangular matrix T1, R1
10 Computing the transitive closure. T1, R1
8. Activity Based Learning
1. Case- studies
9. Lecture Notes

1.1 INTRODUCTION
BRANCH AND BOUND: GENERAL METHOD
Branch and Bound is another method to systematically search a solution space. Just like
backtracking, we will use bounding functions to avoid generating subtrees that do not
contain an answer node. However branch and Bound differs from backtracking in two
important manners:

It has a branching function, which can be a depth first search, breadth first search or based
on bounding function.
It has a bounding function, which goes far beyond the feasibility test as a mean to prune
efficiently the search tree.
Branch and Bound refers to all state space search methods in which all children of the E-
node are generated before any other live node becomes the E-node
• Branch and Bound is the generalization of both graph search strategies, BFS and D-
search.
• A BFS like state space search is called as FIFO (First in first out) search as the list of live
nodes in a first in first out list (or queue).
A D search like state space search is called as LIFO (Last in first out) search as the list of live
nodes in a last in first out (or stack).

• Definition 1: Live node is a node that has been generated but whose children
have not yet been generated.
• Definition 2: E-node is a live node whose children are currently being explored. In otherwords,

2|D A A - U N I T - IV
SVCE KADAPA

an E-node is a node currently being expanded.

• Definition 3: Dead node is a generated node that is not to be expanded or explored any further. All children
of a dead node have already been expanded.
• Definition 4: Branch-an-bound refers to all state space search methods in which all children of an E-node
are generated before any other live node can become the E-node.
• Definition 5: The adjective "heuristic", means" related to improving problem solving
performance".

• As a noun it is also used in regard to "any method or trick used to improve the efficiency of a problem
solving problem". But imperfect methods are not necessarily heuristic or vice versa. "A heuristic
(heuristic rule, heuristic method) is a rule of thumb, strategy, trick simplification or any other kind of
device which drastically limits search for solutions in large problemspaces.

• Heuristics do not guarantee optimal solutions, they do not guarantee any solution at all. A useful heuristic
offers solutions which are good enough most of the time.

LEAST COST (LC) SEARCH

In both LIFO and FIFO Branch and Bound the selection rule for the next E- node in rigid and blind. The
selection rule for the next E-node does not give any preference to a node that has a very good
chance of getting the search to an answer node quickly.

• The search for an answer node can be speeded by using an ―intelligent‖ ranking Function c( .)
for live nodes. The next E-node is selected on the basis of this ranking function. The node x is
assigned a rankusing:

c ( x ) = f(h(x)) + g ( x )
where, c ( x ) is the cost of x.
h(x) is the cost of reaching x from the root and f(.) is any non-decreasing function
g ( x ) is an estimate of the additional effort needed to reach an answer node from x:
A search strategy that uses a cost function c ( x ) = f(h(x) + g ( x ) to select the next E-node would
always choose for its next E-node a live node with least LC–(Least Cost search) c(.) is called a
BFS and D-search are special cases of LC-searchIf g( x ) = 0 and f(h(x)) = level of node x, then an
LC search generates nodes by levels. This is eventually the same as a BFS. If f(h(x)) = 0 and
essentially a D-searchg ( x ) > g ( y ) whenever y is a child of x, then
the search is An LC-search coupled with bounding functions is called an LC-branch and bound
search
We associate a cost c(x) with each node x in the state space tree. It is not possible to easily
compute the function c(x). So we compute a estimate c ( x ) of c(x).
CONTROL ABSTRACTION FOR LC-SEARCH
• Let t be a state space tree and c() a cost function for the nodes in t. If x is a node in t, then
c(x) is the minimum cost of any answer node in the subtree with root x. Thus, c(t) is the cost of
a minimum-cost answer node in t.

3|D A A - U N I T - IV
SVCE KADAPA

• A heuristic c (.) is used to estimate c(). This heuristic should be easy to compute and
generally has the property that if x is either an answer node or a leaf node, then
c(x) =c( x ).
LC-search uses c to find an answer node. The algorithm uses two functions Least() and Add() to
delete and add a live node from or to the list of live nodes, respectively. Least() finds a live node
with least c(). This node is deleted from the list of live nodes and returned
Add(x) adds the new live node x to the list of live nodes. The list of live nodes be
implemented as a min- heap Algorithm LCSearch outputs the path from the answer
node it finds to the root node t. This is easy to do if with each node x that becomes live,
we associate a field parent which gives the parent of node x. When the answer node
g is found, the path from g to t can be determined by following a sequence of parent
values starting from the current E-node (which is the parent of g) and ending at node t
Listnode = record
{
Listnode * next, *parent; float cost;
}
• Algorithm LCSearch(t)
{ //Search t for an answer node
if *t is an answernode thenoutput*t andreturn; E := t;//E-node.
initialize the list of live nodes to be empty; repeat
{
for each child x of E do
{
if x is an answer node then output the path from x to t and return; Add (x);
//x is a new live node.
(x à parent) := E; // pointer for path to root
}
if there are no more live nodes then
{
write (―No answer node‖); return;
}
E := Least();
} until (false);
}
The root node is the first, E-node. During the execution of LC search, this list contains all
live nodes except the E-node. Initially this list should be empty. Examine all the children
of the E-node, if one of the children is an answer node, then the algorithm outputs the
path from x to t and terminates. If the child of E is not an answer node, then it
becomes a live node. It is added to the list of live nodes and its parent field set to E.
When all the children of E have been generated, E becomes a dead node. This
happens only if none of E‟s children is an answer node. Continue the search further
until no live nodes found. Otherwise, Least(), by definition, correctly chooses the next
E-node and the search continues from here.

4|D A A - U N I T - IV
SVCE KADAPA

LC search terminates only when either an answer node is found or the entire state
space tree has been generated and searched.

BOUNDING:
A branch and bound method searches a state space tree using any search
mechanism in which all the children of the E-node are generated before another node
becomes the E-node. We assume that each answer node x has a cost c(x) associated
with it and that a minimum-cost answer node is to be found. Three common search
strategies are FIFO, LIFO, and LC. The three search methods differ only in the selection
rule used to obtain the next E-node.
• A good bounding helps to prune efficiently the tree, leading to a faster exploration of the
solution space
• A cost function c(.) such that c ( x ) < c(x) is used to provide lower bounds on solutions
obtainable from any node x. If upper is an upper bound on the cost of a minimum-cost
solution, then all live nodes x with c(x) >c ( x ) > upper. The starting value for upper can be
obtained by some heuristic or can be set to ∞
• As long as the initial value for upper is not less than the cost of a minimum-cost answer node,
the above rules to kill live nodes will not result in the killing of a live node that can reach a
minimum- cost answer node. Each time a new answer node is found, the value of upper
can be updated.
• Branch-and-bound algorithms are used for optimization problems where, we deal directly
only with minimization problems. A maximization problem is easily converted to a
minimization problem by changing the sign of the objective function.
• To formulate the search for an optimal solution for a least-cost answer node in a state space
tree, it is necessary to define the cost function c(.), such that c(x) is minimum for all nodes
representing an optimal solution. The easiest way to do this is to use the objective function
itself for c(.).
• For nodes representing feasible solutions, c(x) is the value of the objective function for that
feasiblesolution. Fornodesrepresentinginfeasiblesolutions Fornodesrepresentingpartial
solutions, c(x) is the cost of the minimum-cost node in the subtree with root x. Since, c(x) is
generally hard to compute, the branch-and-bound algorithm will use an estimate c ( x )
such that c ( x ) < c(x) for all x.
The 15 – Puzzle Problem:
• The 15 puzzle is to search the state space for the goal state and use the path from the
initial state to the goal state as the answer. There are 16! (16! ≈ 20.9 x 1012) different
arrangements of the tiles on the frame.
• As the state space for the problem is very large it would be worthwhile to determine
whether the goal state is reachable from the initial state. Number the frame positions 1
to 16.
• Position i is the frame position containing title numbered i in the goal arrangement of
Figure 8.1(b). Position 16 is theempty spot. Letposition(i) be the positionnumber inthe
initial state of the title number i. Then position(16) will denote the position of the empty
spot.

5|D A A - U N I T - IV
SVCE KADAPA

• For any state let: less(i) be the number of tiles j such that j < i and position(j) >
position(i).
• The goal state is reachable from the initial state iff

6|D A A - U N I T - IV
SVCE KADAPA

Search for 15 Puzzle Problem:


• A depth first state space tree generation will result in the subtree of Figure
• 8.3 when the next moves are attempted in the order: move the empty space
up, right, down and left. The search of the state space tree is blind. It will take
the leftmost path from the root regardless of the starting configuration. As a
result, the answer node may never be found.
• A breadth first search will always find a goal node nearest to the root.
However, such a search is also blind in the sense that no matter what the
initial configuration, the algorithm attempts to make the same sequence of
moves.
• We need a more intelligent search method. We associate a cost c(x) with
each node x in the state space tree. The cost c(x) is the length of a path from
the root to a nearest goal node in the subtree with root x. The easy to
compute estimate c (x) of c(x) is as follows:
• c (x) = f(x) + g (x)
• where, f(x) is the length of the path from the root to node x and
• g (x) is an estimate of the length of a shortest path from x to a goal node in
the subtree with root x. Here, g (x) is the number of nonblank tiles not in their
goal position.
• An LC-search of Figure 8.2, begin with the root as the E-node and generate all
child nodes 2, 3, 4 and 5. The next node to become the E-node is a live node
with least .
• c (x).
• c (2) = 1 + 4 = 5
• c (3) = 1 + 4 = 5
• c (4) = 1 + 2 = 3 and
• c(5) = 1 + 4 = 5.

7|D A A - U N I T -
SVCE KADAPA

• Node 4 becomes the E-node and its children are generated. The live nodes at
this
• time are 2, 3, 5, 10, 11 and 12. So:
• c(10) = 2 + 1 = 3
• c (11) = 2 + 3 = 5 and
• c (12) = 2 + 3 = 5.

• The live node with least c is node 10. This becomes the next E-node. Nodes 22 and 23 are
generated next. Node 23 is the goal node, so search terminates.
LC-search was almost as efficient as using the exact function c(), with a suitable choice for c
(), LC-search will be far more selective than any of the other search methods.

8|D A A - U N I T - IV
SVCE KADAPA

0/1 KNAPSACK:
• Given n positive weights wi, n positive profits pi, and a positive number m that is the knapsack capacity,
the problem calls for choosing a subset of the weights such that:
SVCE TIRUPATI

• The xi‟s constitute a zero–one-valued vector.


• The solution space for this problem consists of the 2n distinct ways to assign zero or one
values to the xi‟s.
• Bounding functions are needed to kill some live nodes without expanding them. A good
bounding function for this problem is obtained by using an upper bound on the value of the
best feasible solution obtainable by expanding the given live node and any of its
descendants. If this upper bound is not higher than the value of the best solution determined
so far, than that live node can be killed.
• We continue the discussion using the fixed tuple size formulation. If at node Z the values of xi,
1 < i < k, have already been determined, then an upper bound for Z can be obtained by relaxing the
requirements xi = 0 or 1.
• (Knapsack problem using backtracking is solved in branch and bound chapter)
0/1 KNAPSACK PROBLEM
• Consider the instance: M= 15, n= 4, (P1, P2, P3, P4) = (10, 10, 12, 18) and(w1, w2, w3, w4) =(
2, 4, 6, 9).
• 0/1 knapsack problem can be solved by using branch and bound technique. In this problem
we will calculate lower bound and upper bound for each node.
• Place first item in knapsack. Remaining weight of knapsack is 15 – 2 = 13. Place next item w2

9|D A A - U N I T -
BTECH_IT-SEM 31
SVCE KADAPA

in knapsack and the remaining weight of knapsack is 13 – 4 = 9. Place next item w3 in


knapsack then the remaining weight of knapsack is 9 – 6 = 3. No fractions are allowed in
calculation of upper bound so w4 cannot be placed in knapsack.
• Profit = P1 + P2 + P3 = 10 + 10 + 12
• So, Upper bound = 32
• To calculate lower bound we can place w4 in knapsack since fractions are allowed in
calculation of lower bound.
• Lower bound = 10 + 10 + 12 + ( 3 X 18) = 32 + 6 = 38
• Knapsack problem is maximization problem but branch and bound technique is applicable
for only minimization problems. In order to convert maximization problem into minimization
problem we have to take negative sign for upper bound and lower bound.
• Therefore, Upper bound (U) = -32
• Lower bound (L) =-38
• We choose the path, which has minimum difference of upper bound and lower bound. If
the difference is equal then we choose the path by comparing upper bounds and we
discard node with maximum upper bound.

10|D A A - U N I T - IV
SVCE KADAPA

11|D A A - U N I T - IV
KAD
APA

Now we will calculate lower bound and upper bound of node 4 and Calculate
difference of lower and upper bound of nodes 4 and 5.
For node 8, U – L = -38 + 38 = 0
For node 9, U – L = -20 + 20 = 0
Here the difference is same, so compare upper bounds of nodes 8 and 9.
Discard the node, which has maximum upper bound. Choose node 8, discard node 9
since, it has maximum upper bound. Consider the path from 1 -> 2 -> 4 ->7 -> 8
X1 = 1
X2 = 1
X3 = 0
For node 8, U – L = -38 + 38 = 0
For node 9, U – L = -20 + 20 = 0
Here the difference is same, so compare upper bounds of nodes 8 and 9. Discard the
node, which has maximum upper bound. Choose node 8, discard node 9 since, it has
maximum upper bound.
Consider the path from 1 -> 2 -> 4 ->7 -> 8
X1 = 1
X2 = 1
X3 = 0
X4 = 1
The solution for 0/1 Knapsack problem is (x1, x2, x3, x4) = (1, 1, 0, 1) Maximum profit is:
Pi xi = 10 x 1 + 10 x 1 + 12 x 0 + 18 x 1

12|D A A - U N I T - IV
BTECH_ICTS-ES-ESMEM
3132
SVCE KADAPA
= 10 + 10 + 18 = 38.
0/1 KNAPSACK PROBLEM :

• N items of known weights wi and values vi, i=1,2,….n


• Knapsack capacity W =10
Item Weight Value Value/Weight

1 4 $40 10

2 7 $42 6

3 5 $25 5

4 3 $12 4

State Space tree of knapsack problem

TRAVELING SALE PERSON (TSP) USING BACKTRACKING


• We have solved TSP problem using dynamic programming. In this section we
shall solve the same problem using backtracking
• For each city i, 1 <= i <=n, find the sum of the distances from city i to the two
nearest cities.
• Compute the sum s of these n numbers
• Divide the result by 2
• If all the distances are integers, round up the result to the nearest integer • lb = [
s/2 ]

13|D A A - U N I T - IV
Thesolution

space tree, similar to the n-queens problem is as follows:

• We will assume that the starting node is 1 and the ending node is obviously 1. Then 1, {2, …
,4}, 1 forms a tour with some cost which should be minimum. The vertices shown as {2, 3, ….
,4} forms a permutation of vertices which constitutes a tour. We can also start from any
vertex, but the tour should end with the same vertex.
• Since, the starting vertex is 1, the tree has a root node R and the remaining nodes are
numbered as depth-first order. As per the tree, from node 1, which is the live node, we
generate 3 braches node 2, 7 and 12.
• We simply come down to the left most leaf node 4, which is a valid tour {1, 2, 3, 4, 1} with
cost 30 + 5 + 20 + 4 = 59. Currently this is the best tour found so far and we backtrack to
node 3 and to 2, because we do not have any children from node 3.
• When node 2 becomes the E- node, we generate node 5 and then node 6. This forms
the tour {1, 2, 4, 3, 1} with cost 30 + 10 + 20 + 6 = 66 and is discarded, as the best tour so

14|D A A - U N I
BTECH_IT-SEM 31
SVCE KADAPA
far is 59.
• Similarly, all the paths from node 1 to every leaf node in the tree is searched in a depth
first manner and the best tour is saved. In our example, the tour costs are shown
adjacent to each leaf nodes. The optimal tour cost is therefore 25.

TRAVELING SALES PERSON

By using dynamic programming algorithm we can solve the problem with time
complexity of 0(n22n )for worst case, This can be solved by branch and bound
technique using efficient bounding function, The time complexity of traveling sale
person problem using LC branch and bound is 0(n22n ) which shows that there is
no change or reduction of complexity than previous method,
We start at a particular node and visit all nodes exactly once and come back to
initial node with minimum cost.
Let G = (V, E) is a connected graph, Let C(i, J) be the cost of edge <i, j>, cij = ∞ if
<i, j> €Eand let IVI = n, the number ofvertices, Every tour starts at vertex 1 and
ends at the same vertex, So, the solution space is given by S = {1,∏,1 I ,∏ is a
permutation of (2, 3,…, n)} and ISI = (n - 1)!. The size of S can be reduced by
restricting S so that (1, i1,i2,….in-1,1) s iff <ij,I j+ 1) € E, 0 ≤j ≤ n-1 andi0=in=1.

Procedure for solving traveling sale person problem:

1. Reduce the given cost matrix. A matrix is reduced if every row and column is reduced. A row
(column) is said to be reduced if it contain at least one zero and all-remaining entries are non-
negative. This can be done as follows:
• a) Row reduction: Take the minimum element from first row, subtract it from all elements of
first row, next take minimum element from the second row and subtract it from second row.
Similarly apply the same procedure for all rows.
• b) Find the sum of elements, which were subtracted from rows.
c) Apply column reductions for the matrix obtained after row reduction.
• Columnreduction: Take the minimum element from first column, subtract it from all elements
of first column, next take minimum element from the second column and subtract it from
second column. Similarly apply the same procedure for all columns.
• d) Find the sum of elements, which were subtracted from columns.
• e) Obtain the cumulative sum of row wise reduction and column wise reduction.
• Cumulative reduced sum = Row wise reduction sum + column wise reduction sum.
• Associate the cumulative reduced sum to the starting state as lower
• bound and ∞ as upper bound.

15|D A A - U N I
BTECH_IT-SEM 31
SVCE

3. Repeat step 2 until all nodes are visited

LOWER BOUND THEORY

NOTE: our labeling of the nodes refers to the list elements, not to their positions at the time the
comparison corresponding to a given node is made.
The following figure illustrates the comparison-tree associated with Insertion Sort for a list
L[0:2] of 3 distinct elements x1, x2, x3.

16|D A A - U N I T - IV
SVCE

• Key Fact. The comparision tree associated with any comparison-based sorting
algorithm has n! leaf nodes.

• The Key Fact follows from the fact that there are n! factorial permutations of n
symbols, and different permutations must end up at different leaf nodes of the
comparison tree when input to the algorithm. Since the comparison tree associated
with a comparison-based sorting algorithm is a binary tree, lower bounds for both
worst-case and average complexity can be obtained from lower bounds for the
depth and leaf path length (= sum of the lengths of all paths from the root to a
leaf), respectively, of a binary tree having L leaf nodes.
Proposition 1. Let T be any binary tree with L leaf nodes. Then
Depth(T)≥ ceil(log2L)
• Proposition 1 is clearlytrueforcomplete binarytrees(verify this!), so it is intuitively
evident that it holds for arbitrary binary trees since the complete binary tree has the
smallest depth for a given number L of leaf nodes. The formal proof of Proposition 1
can be found on p. 120 in the text. It follows immediately from Proposition 1 that
• W(n) ≥ ceil(log2L)
• for any comparison-based sorting algorithm. Now, ceil(log2L) = ceil(log2n!) ∈ Ω(nlog n),
so that we have established another proof of the fact that nlog n is a lower bound for
the worst-case complexity of comparison-based sorting.
• The following Proposition will give us a lower bound of nlog n for the average case as
well.
• Proposition 2. Let T be any binary tree having L leaf nodes. Then the leaf path length
LPL of Tsatisfies:
• LPT(T) ≥ Lfloor(log2L) ∈ Ω(Llog L)

17|D A A - U N I T - IV
I
SVCE KADAPA
MULTIPLIYING TRIANGULER MATRIX

18|D A A - U N I T - IV
I
SVCE KADAPA
LEMMA 10.5 Mt (n) = Ω (m(N))

19|D A A - U N I T - IV
I
SVCE KADAPA
Lemma 10.6 M(n) = O (It (nn)).

1.9 COMPUTING THE TRANSITIVE CLOSURE

Lemma 10.8 Let A be the adjacency matrix of a given directed graph G. Then,
Ak(i,j) = 1 if and only if there is a path from node i to node j of length exactly
equal to k, for any 0 ≤ k ≤ n. Here the matrix products are interpreted as follows:
Scalar addition corresponds to boolean or and scalar multiplication corresponds
to boolean and.
Proof: We prove the lemma by induction on k. When k = 0, A° is the identity matrix
and the lemma holds, since there is a path of length zero from every node to
itself. When k = 1, the lemma is also true, since A(i,j) = 1 if and only if there is an
edge from i to j. Assume that the lemma is true for all path lengths up to k —1, k >

20|D A A - U N I T - IV
I
SVCE TIRUPATI
1. We prove it for a path length of k.

If there is a path of length k from node i to node j, this path consists of an edge
from node i to some other node q and then a path from q to j of length k —1. In
other words, using the induction hypothesis, there exists a q such that A(i,q) =--1
and A k-1(q,j) = 1. If there is such a q, then Ak(i,j) = (A * Ak-1)(i,j) is surely 1.

Conversely, if Ak(i,j) = 1, then since Ak = A *A k-1, there exists a q such that A(i, q) =1
and Ak-1 (q,j) = 1. This means that there is a path from node i to node j of length k.
If there is a path at all from node i to node j in G, the shortest such path will be of
length ≤ (n — 1), n being the number of nodes in G.

21|D A A - U N I T - IV
I
SVCE KADAPA
9. Practice Quiz

1. The term 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
(a) Branch and bound
(b) Modular arithmetic
(c) interpolation
(d) transformation
2. A search strategy that uses a cost function to select the next E-node would always choose for its next E-
node a live node with least _ _ _ _ _ _ _ _ _ _
(a) FIFO function
(b) LIFO function
(c) Cost function
(d) Branch function
3. A maximization problem is easily converted to a minimization problem _ __
(a) by changing the sign of the objective function
(b) by taking the reciprocal of the objective function
(c) by taking the square root of the objective function
(d) by taking the functional value of the objective function
4. We start at a particular node in the graph, visiting all nodes exactly once and come back to initial node
with minimum cost. This is known as _ _ _ _ _ _ _
(a) 0/1 knapsack problem
(b) optimal storage on tapes
(c) minimum cost spanning tree
(d) traveling sales person problem
5. If M=15, n=4, P1, P2, P3, P4=(10,10,12,18) and W1,W2, W3,W4=(2,4,6,9) of 0/1 knapsack problem
then using LC branch-and-bound search, the upper bound of node 1 is _ _ _ _
(a) -32
(b) -34
(c)-36
(d)-38

22|D A A - U N I T - IV
I
SVCE KADAPA
10. ASSIGNMENTS

S.No Question BL CO

1 Explain about travelling salesman problem with example. 2 1


2 Explain about 0/1 knapsack problem 3 2
Write a difference between branch and bound with backtracking.
3 2 1
4 Explain lower bounds through reductions. 2 2
5 What is Triangular matrices ? Explain about multiplying triangular 3 1
matrices

11. Part A- Question & Answers

S.No Question& Answers BL CO


1 Define Branch-and-Bound method.

The term Branch-and-Bound refers to all the state space methods 1 1


in which all children of the E-node are generated before any
other live node can become the E- node.
2 Define LCBB.

In LCBB we have to calculate lower bound and upper bound.


• While calculating lower bound for a node in state space
1 1
tree the fractions are allowed
• While calculating upper bound for a node in state space
tree the fractions are not allowed.
• In LCBB the node is expanded based on the minimum lower
bound of a node in state space tree.
3 Define FIFOBB

• In FIFOBB we have to calculate lower bound, upper bound


and global upper bound. 1 1
• While calculating lower bound for a node in state space
tree the fractions are allowed
• While calculating upper bound for a node in state space
tree the fractions are not allowed.
• In FIFOBB the node is expanded based on the global upper
bound by following two conditions. They are:
• If lower bound of a node in state space tree is greater than
the global upper bound then we will kill the node, otherwise we
expand the node
• If new upper bound of a node in state space tree is less
than the global upper bound then the global upper bound is
updated.

23|D A A - U N I T - IV
I
SVCE KADAPA
12. Part B

S.No Question B CO
L
1 Explain about travelling salesman problem with example. 1 1

2 Explain about 0/1 knapsack problem 2 1


3 Write a difference between branch and bound with 2 1
backtracking.
4 Define briefly about the algorithms in Lower bound theory? 3 1
5 What is Triangular matrices ? Explain about multiplying triangular 3 1
matrices

Supportive Online Certification Courses


1. Design and analysis of algorithms By Prof. Abhiram Ranade, conducted by IIT Bombay – 34
Lectures
2. Fundamental algorithms: Design and Analysis By Prof. Sourav mukhopadhyay, conducted
by IIT Kharagpur – 4 weeks.
Real Time Applications
S.No Application CO
1 The TSP naturally arises as a subproblem in many transportation and 1
logistics applications, for example the problem of arranging school bus
routes to pick up the children in a school district.

2 The TSP is involved in transportation of farming equipment from one 1


location to another to test soil

3 The TSP applications involve the scheduling of service calls at cable firms, 1
the delivery of meals to homebound persons, the scheduling of stacker
cranes in warehouses, the routing of trucks for parcel post pickup, and a
host of others.

13. Contents beyond the Syllabus


• Adversary Arguments: a method of proving a lower bound by playing role of adversary that
makes algorithm work the hardest by adjusting input.
14. Prescribed Text Books & Reference Books
Text Book
1. Fundamentals of Computer Algorithms, Ellis Horowitz, S. Satraj Sahani and Rajasekhran, 2nd
edition, University Press.2014,
2. Design and Analysis of Algorithms, Parag Himanshu Dave, Himanshu Bhalchandra Dave,
Pearson Education, Second Edition, 2009.
References:
1. Introduction to Algorithms, second edition, T.H.Cormen, C.E.Leiserson, R.L.Rivest and
C.Stein, PHI Pvt. Ltd./ Pearson Education.

24|D A A - U N I T - IV
I
SVCE TIRUPATI
2. Introduction to Design and Analysis of Algorithms
A strategic approach, R.C.T.Lee, S.S.Tseng, R.C.Chang and T.Tsai, Mc Graw Hill.
11. Mini Project Suggestion
1. A Parallel Architecture for the Generalized Travelling Salesman Problem: Project Proposal
The goal of this project is to develop a parallel implementation of a serial heuristic to attack
large instances of the generalized travelling salesman problem (GTSP). By leveraging more
computational resources the parallel version of the heuristic is expected to produce higher-
quality solutions in less time. A significant portion of this project will involve the development
of a parallel architecture that can be extended to host a selected serial heuristic and the
GTSP problem class. The extension of the architecture to host the serial heuristic will involve
the identification and implementation of different methods of parallel cooperation and
levels of parallelism. The parallel heuristic will be tested on a database of problem instances
and the performance will be compared to published results of the serial heuristic. In
addition, the parallel heuristic will be tested to determine how performance scales with the
number of processorsused.

25|D A A - U N I T - IV
I
SVCE KADAPA

26|D A A - U N I T - IV

You might also like