DAA - Internal 2 QP (With Key)
DAA - Internal 2 QP (With Key)
No:
Implement and analyze the problems using dynamic programming and greedy algorithmic
CO3
techniques.
CO4 Solve the problems using iterative improvement techniques for optimization.
Compute the limitations of algorithmic power and solve the problems using backtracking
CO5
and branch and bound techniques.
BL – Bloom’s Taxonomy Levels.
(L1-Remembering, L2-Understanding, L3- Applying, L4-Analyzing, L5- Evaluating, L6-Creating)
PART – A (10 2=20 Marks)
1. What do you mean by dynamic programming? L1 CO3
2. Define Bipartite graph? L1 CO3
3. Define Augmenting path? L1 CO4
4. What is blocking pad? L1 CO4
5. Define backtracking and branch & bound technique? L1 CO5
PART – B [2 X 13 = 26 Marks]
a) Construct optimal binary seacrh tree with suitable example? 13 L2 CO3
6.
OR
b) Discuss in detail stable marriage problem? CO3
13 L2
L3
a) Explain travelling salesman using branch and bound technique? 13 CO4
7. OR
L2
b) Explain in detail about job assignment problem? 13 CO5
PART – C [1 X 14 = 14 Marks]
a) ) Give any 5 undecidable problem and explain the famous halting problem? 14 L2 CO4
8.
OR
CO5
b) Explain P, NP, NP complete and NP hard? 14 L1
PART-B
6A) OPTIMAL BINARY SEARCH TREE Problem:
Given n keys a1 < …< an and probabilities p1, …, pn searching for them, find a
BST with a minimum average number of comparisons in successful search.
Since total number of BSTs with n nodes is given by C(2n,n)/(n+1), which
grows exponentially, brute force is hopeless.
Let C[i,j] be minimum average number of comparisons made in T[i,j], optimal
BST for keys ai < …< aj , where 1 ≤ i ≤ j ≤ n. Consider optimal BST among all
BSTs with some ak (i ≤ k ≤ j ) as their root; T[i,j] is the best among them.
The recurrence for C[i,j]:
C[i,j] = min {C[i,k-1] + C[k+1,j]} + ∑ ps for 1 ≤ i ≤ j ≤ n
C[i,i] = pi for 1 ≤ i ≤ j ≤ n
C[i, i- 1] = 0 for 1≤ i ≤ n+1 which can be interpreted as the number of
comparisons in the empty tree.
01jn
1 0 p 1 goal
EXAMPLE
Let us illustrate the algorithm by applying it to the four key set we used at the
beginning of this section:
KEY A B C D
Initial Tables:
Main Table Root Table
01234 01234
1 0 0.1 11
2 0 0.2 22
3 0 0.4 33
4 0 0.3 5 0 445
K=2: c(1,2) = c(1,1) + c(3,2) + 0.1 + 0.2 = 0.1 + 0 + 0.1 + 0.2 = 0.4
0 1 2 3 4 0 1 2 3 4
1 0 0.1 0.4 1 1 2
2 0 0.2 2 2
3 0 0.4 3 3
4 0 0.3 4 4
5 0 5
K=3: c(2,3) = c(2,2) + c(4,3) + 0.2 + 0.4 = 0.2 + 0 + 0.2 + 0.4 = 0.8
01234 01234
1 0 0.1 0.4 112
2 0 0.2 0.8 223
3 0 0.4 33
4 0 0.3 5 0 445
K=4: c(3,4) = c(3,3) + c(5,4) + 0.4 + 0.3 = 0.4 + 0 + 0.4 + 0.3 = 1.1
01234
1 0 0.1 0.4
2 0 0.2 0.8
3 0 0.4 1.0 4 0 0.3 5 0
K=2: c(1,3) = c(1,1) + c(3,3) + 0.1 + 0.2 + 0.4 = 0.1 + 0.4 + 0.1 + 0.2 + 0.4 = 1.2
K=3: c(1,3) = c(1,2) + c(4,3) + 0.1 + 0.2 + 0.4 = 0.4 + 0 + 0.1 + 0.2 + 0.4 = 1.1
0 1 2 3 4 0 1 2 3 4
2 0 0.2 0.8 2 2 3
3 0 0.4 1.0 3 3 3
4 0 0.3 4 4
5 0 5
K=3: c(2,4) = c(2,2) + c(4,4) + 0.2 + 0.4 + 0.3 = 0.2 + 0.3 + 0.2 + 0.4 + 0.3 = 1.4
K=4: c(2,4) = c(2,3) + c(5,4) + 0.2 + 0.4 + 0.3 = 0.8 + 0 + 0.2 + 0.4 + 0.3 = 1.7
01234 01234
1 0 0.1 0.4 1.1 1123
2 0 0.2 0.8 1.4 3 0 0.4 1.0 4 0 0.3 5 0 2 2 3 3 3 3 3 4 4 5
0 1 2 3 4 0 1 2 3 4
3 0 0.4 1.0 3 3 3
4 0 0.3 4 4
5 0 5
Thus, the average number of key comparisons in the optimal tree is equal to
1.7.
key D.
Since R(1, 4) = 3, the root of the optimal tree contains the third key, i.e., C. Its
left subtree is made up of keys A and B, and its right subtree contains just
Since R(1, 2) = 2, the root of the optimal tree containing A and B is B, with A
being its left child (and the root of the one node tree: R(1, 1) = 1).
(OR)
Marriage Matching:
Lower bound if edge (b,e) is chosen. The path taken will be (a ->b->e):
lb = ceil([(3+1)+(3+9)+(2+9)+(1+2)+(4+3)]/2)=19. (Since this lb is larger than other values,
so further expansion is stopped)
The path a->b->c and a->b->d are more promising. Hence the state space tree is
expanded from those nodes.
Next level
There are four possible routes:
a ->b->c->d->e->a a
->b->c->e->d->a a-
>b->d->c->e->a a-
>b->d->e->c->a
Lower bound for the route a ->b->c->d->e->a: (a,b,c,d)(e,a) lb =
ceil([(3+8)+(3+6)+(6+4)+(4+3)+(3+8)])
Lower bound for the route a ->b->c->e->d->a: (a,b,c,e)(d,a) lb =
ceil([(3+5)+(3+6)+(6+2)+(2+3)+(3+5)]/2)=19
Lower bound for the route a->b->d->c->e->a: (a,b,d,c)(e,a)
lb =
ceil([(3+8)+(3+7)+(7+4)+(4+2)+(2+8)]/2)
=24
Lower bound for the route a->b->d->e->c->a: (a,b,d,e)(c,a)
lb =
ceil([(3+1)+(3+7)+(7+3)+(3+2)+(2+1)]/2)
=16
Therefore from the above lower bound the solution is The
optimal tour is a ->b->c->e->d->a
(OR)
To find a lower bound on the cost of an optimal selection without actually solving the
problem, several methods can be used. For example, it is clear that the cost of any
solution, including an optimal one, cannot be smaller than the sum of the smallest
elements in each of the matrix‗s rows. For the instance given, the lower bound is lb= 2
+3 + 1 + 4 = 10.
It is important to stress that this is not the cost of any legitimate selection (3 and 1
came from the same column of the matrix); it is just a lower bound on the cost of any
legitimate selection.
Apply the same thinking to partially constructed solutions. For example, for any
legitimate selection that selects 9 from the first row, the lower bound will be lb = 9 + 3 +
1 + 4 = 17.
This problem deals with the order in which the tree‗s nodes will he generated. Rather
than generating a single child of the last promising node as in backtracking, all the
children of the most promising node among non- terminated leaves in the current tree
are generated.
To find which of the nodes is most promising, compare the lower bounds of the live
node. It is sensible to consider a node with the best bound as most promising, although
this does not, of course, preclude the possibility that an optimal solution will ultimately
belong to a different branch of the state-space tree.
This variation of the strategy is called the best-first branch-and-bound.
Returning to the instance of the assignment problem given earlier, start with the root
that corresponds to no elements selected from the cost matrix. As the lower bound
value for the root, denoted lb is 10.
The nodes on the first level of the free correspond to four elements (jobs) in the first
row of the matrix since they are each a potential selection for the first component of the
solution. So there are four live leaves (nodes 1 through 4) that may contain an optimal
solution. The most promising of them is node 2 because it has the smallest lower bound
value.
By following the best-first search strategy, branch out from that node first by
considering the three different ways of selecting an element from the second row and
not in the second column—the three different jobs that can be assigned to person b.
Of the six live leaves (nodes 1, 3, 4, 5, 6, and 7) that may contain an optimal solution, we
again choose the one with the smallest lower bound, node 5.
First, consider selecting the third column’s element from c‗s row (i.e., assigning person c
to job 3); this leaves with no choice but to select the element from the fourth column of
d‗s row (assigning person d to job 4). This yield leafs that corresponds to the feasible
solution (a →2, b→1, c→3, d →4) with (The total cost of 13. Its sibling, node 9,
corresponds to the feasible
Solution:
solution {a → 2, b →1, c → 4, d → 3) with the total cost of 25, Since its cost is larger than
the cost of the solution represented by leafs, node 9 is simply terminated. o Note that if
its cost were smaller than 13 then it would have to be replaced with the information
about the best solution seen so far with the data provided by this node. o Now, as
inspect each of the live leaves of the last state-space tree (nodes 1, 3, 4, 6, and 7 in the
following figure), it is discovered that their lower bound values are not smaller than 13
the value of the best selection seen so far (leaf 8).
o Hence all of them are terminated and the solution represented by leaf 8 is recognized
as the optimal solution to the problem.
PART-C
8a)
(OR)
8b)