Professional Documents
Culture Documents
(19ECS234)
G V Sivanarayana
Assistant Professor
Department of CSE
GITAM Institute of Technology (GIT)
Visakhapatnam – 530045
03 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 1
Topics to be Covered
Dynamic Programming: The general method, multistage graphs, all pairs shortest
paths, optimal binary search trees, reliability design, the travelling sales person
problem.
03 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19EID237 and Data Structures with Python GVSN 3
Learning Outcomes:
After completion of this unit, the student will be able to
● Compare dynamic method with previous methods (L2)
● Apply dynamic method for developing algorithms (L3)
● Illustrate the merits of dynamic method (L2)
● Analyze the performance of algorithms (L4)
03 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19EID237 and Data Structures with Python GVSN 4
DYNAMIC PROGRAMMING
Divide & Conquer algorithm partition the problem into disjoint subproblems solve the subproblems
recursively and then combine their solution to solve the original problems.
Dynamic Programming is used when the subproblems are not independent, e.g. when they share the
same subproblems. In this case, divide and conquer may do more work than necessary, because it
Dynamic Programming is a Bottom-up approach, we solve all possible small problems and then
03 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 5
DYNAMIC PROGRAMMING
The idea is to simply store the results of subproblems, so that we do not have to re-compute them when
needed later.
This simple optimization reduces time complexities from exponential to polynomial.
For example, if we write simple recursive solution for Fibonacci Numbers, we get exponential time
complexity and if we optimize it by storing solutions of subproblems, time complexity reduces to
linear.
int fib(int n) f[0] = 0
{ f[1] = 1
if (n <= 1) Dynamic Programming : Linear
return 1; for (i=2; i <=n; i++)
return fib(n-1) + fib(n-2); f[i] = f[i-1] + f[i-2];
}
return f[n];
Recursion : Exponential
03 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 6
DYNAMIC PROGRAMMING
Dynamic programming is required to take into account the fact that the problems may not be
The sub problem is solved only once and the answer saved in a table thereby avoiding the
03 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 7
ALL PAIRS SHORTEST PATHS
The all pair shortest path algorithm is also known as Floyd-Warshall algorithm is used to find all pair
shortest path problem from a given weighted graph.
As a result of this algorithm, it will generate a matrix, which will represent the minimum distance from
any node to all other nodes in the graph.
At first the output matrix is same as given cost matrix of the graph. After that the output matrix will be
updated with all vertices k as the intermediate vertex.
We initialize the solution matrix same as the input graph matrix as a first step.
Then we update the solution matrix by considering all vertices as an intermediate vertex.
The idea is to one by one pick all vertices and updates all shortest paths which include the picked
vertex as an intermediate vertex in the shortest path.
03 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 8
ALL PAIRS SHORTEST PATHS
03 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 9
Example
6
1
4
2 A0 1 2 3
11 1 0 4 11
3 2
2 6 0 2
3
3 3 ∞ 0
08 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN
A1 ( 1, 1) K=1 , i=1 , j=1
Ak (i , j) = min {Ak-1 (i , j) , Ak-1 (i , k) + Ak-1 (k , j) } , k ≥ 1
08 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN
A3 ( 1, 3) K=3 , i=1 , j=3
Ak (i , j) = min {Ak-1 (i , j) , Ak-1 (i , k) + Ak-1 (k , j) } , k ≥ 1
08 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN
Algorithm Allpaths( cost, A, n)
// cost[1:n, 1:n] is the cost adjacency matrix of a graph with n vertices;
// A[i , j] is the cost of a shortest path from vertex i to vertex j .
// cost[i , i]=0 , for 1 ≤ i ≤ n.
{
for i:= 1 to n do
for j:= 1 to n do
A[i , j] = cost [i , j]; // copy cost into A.
for k:= 1 to n do
for i:= 1 to n do
for j:= 1 to n do
A[ i , j]= min(A[ i , j], A[ i , k]+ A[ k , j]);
}
08 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 14
MULTISTAGE GRAPHS
15 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 15
Backward approach
4
A D 18
1 9
11
2 5 13
s B E t
16
5 C F 2
2
V1 V2 V3 V4
2 t
s B
5 s C F t
C
D
4
A t
11
15 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 21
RELIABILITY DESIGN
In reliability design, the problem is to design a system that is composed of several devices connected in series.
Let ri be the reliability of device Di. Then, the reliability of the entire system is ri. ( – product operation)
D1 D2 D3 .... Dn
In this design, when devices are connected in a series, then if any of the device not working due to any
hardware or software issues, then entire system will not work because all devices are connected serially.
To solve this issue, if we can design a machine with duplicate devices in every stage, then if any of the devices
gets the problem, other duplicate devices will handle the job.
16 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 22
If we duplicate the devices at each stage then the reliability of the system can be increased.
If stage i contains mi copies of devices Di , then the probability that all mi have a malfunction is (1 - ri)mi .
16 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 23
Let assume that the reliability of stage i is given by function Øi (mi) i≤ n.
The reliability of the system of stages is
The reliability design problem is to use device duplication to maximize reliability.
But this maximization is to be carried out under a cost constraint.
Let ci be the cost of each unit of device i and let C be the maximum allowable cost of the system being
designed.
Maximize maximize the reliability
Subject to ≤ C where ≥ 1 ,
under the constraint is devices cost in all stages should not be greater than the total cost of the machine.
ui = [ (C+ - ] [C- Total Cost, ci – cost of device in that stage, cj – sum of all devices cost]
ui how many number of maximum duplicate devices we can design in that stage
16 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 24
• Design a three stage system with device types D1 , D2 , D3 . The cost are $30 , $ 15 , $ 20 respectively. The
cost of the system is to be no more than $105. The reliability of each device type is 0.9 , 0.8 , 0.5
respectively.
u2 = [ (C+ - ]
sol: c1 = 30 , c2 = 15 , c3 = 20
= [( 105+15- (c1+ c2+ c3))/15]
r1 = 0.9 , r2 = 0.8 , r3 = 0.5
= [(120-(30+15+20))/15]
C=105
= 55/15=3.66=3
ui = [ (C+ - ]
u3 = [ (C+ - ]
u1 = [ (C+ - ]
= [( 105+20- (c1+ c2+ c3))/20]
= [( 105+30- (c1+ c2+ c3))/30]
= [(125-(30+15+20))/20]
= [(135-(30+15+20))/30]
= 60/20=3
= 70/30=2.33=2
19 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 25
c1 = 30 , c2 = 15 , c3 = 20
C=105
D1
D1
19 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 26
c1 = 30 , c2 = 15 , c3 = 20
D2
r1 = 0.9 , r2 = 0.8 , r3 = 0.5 D2
D1 D1 D2
D2
C=105
D2 D1
D2
D1 D2 D1
S1 = {( 0.9 , 30) , ( 0.99 , 60)} D1 D2
1D1 2D1
0.9 X 0.8 = 0.72
=1 – 0.008 D1 D2
= ( 0.792 , 75) D1 D2
= 0.992
S = ( 0.864 , 60)
2
2
=1 – (1- 0.8)2
0.9 X 0.992 = 0.8928
=1 – (0.2)2
= ( 0.95 , 90) =1 – 0.04
0.99 X 0.992 = 0.982
= 0.96
S32 = (0.892 , 75)
0.9 X 0.96 = 0.864
= ( 0.982 , 105) 0.99 X 0.96 = 0.95
1D1,1D2 1D1,2D2 2D1,1D2 1D1,3D2 2D1,2D2 2D1,3D3
S =2021,03:00-03:50
2
19 March { ( 0.72 , 45),P.M (0.864 , 60) ( 0.792
Department , 75)
of CSE, GIT , (0.892 ,Course
75),Code
( 0.95 , 90) , ( 0.982
and Title:19ECS234 , 105)}
and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 27
(1D1 , 1D2) (1D1 , 2D2) (1D1 , 3D2) D2
D3
D1 D2 D1 D2 D3
S2 = { ( 0.72 , 45) , (0.864 , 60) , (0.892 , 75)}
S13 = ( 0.36 , 65) 0.864 X 0.5 = 0.432 0.72 X 0.5 = 0.36
D2 D3
D3
= ( 0.432 , 80) D1 D2 D1 D2
D3 D3
= ( 0.446 , 95) 1- (1- 0.5)2
0.864 X 0.75 = 0.648
S 3
= ( 0.54 , 85) D2 =1- (0.5)2
2
D2 = 1- 0.25= 0.75
D3 0.72 X 0.75 = 0.54
= ( 0.648 , 100) D1
D2 D3
S33 = ( 0.63 , 105) D1 D2 D3
0.892 X 0.5 = 0.446 D3
1- (1- 0.5)3
=1- (0.5)2
S = { ( 0.36
3
, 65)
1D1,1D 2,1D3
, (0.432
1D1,2D,2,1D
80)3 , (0.54 , 85)
1D1,1D , ( 0.446
2,2D3 1D1,3D,2,1D
95)3 , ( 0.648
1D1,2D,2,2D
100)
3
, ( 0.63
1D1,1D, 2105)
,3D3 } = 1- 0.125= 0.875
0.72 X 0.875 = 0.63
Maximum Reliability = 1D1,2D2,2D3 = (0.648 , 100)
D2 D3
D1
D2 D3
19 March 2021,03:00-03:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 29
TRAVELING SALESPERSON PROBLEM
The variable cij is defined such that cij > 0 for all i and j and cij = ∞ if ( i , j )
A tour of G is a directed simple cycle that includes every vertex in V. The cost of a tour is the sum
of the cost of the edges on the tour.
The traveling salesperson problem is to find a tour of minimum cost.
g( i , S ) = min {cij + g( j , S – { j} )}
where i – choosen vertex, S – set of all other vertices in the graph Ex: g(1,{2,3,4}) = min{c12 + g(2, {3,4})
cij – cost from i to j (j is one of the vertex from set S)
g( i , S ) = min {cij + g( j , S – { j} )}
Source vertex j
g( 3 , Ø , 1) = c31 = 6
g( 4 , Ø , 1) = c41 = 8
23 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 31
g( 2 , 3 , 1) = c23 + g( 3, 1) = 9+6 = 15
When |S| = 1
g( 2 , 4 , 1) = c24 + g( 4, 1) = 10+8 = 18
1 2 3 4
g( 3 , 2 , 1) = c32 + g( 2, 1) = 13+5 = 18
1 0 10 15 20
g( 3 , 4 , 1) = c34 + g( 4, 1) = 12+8 = 20 2 5 0 9 10
g( 4 , 2 , 1) = c42 + g( 2, 1) = 8+5 = 13 3 6 13 0 12
4 8 8 9 0
g( 4 , 3 , 1) = c43 + g( 3, 1) = 9+6 = 15
g( 2 , {3,4} , 1) = min {c23 + g( 3, 4 ,1) , c24 + g( 4, 3 ,1) }
= min { (9 + 20) , (10 + 15) } = 25
g( 3 , {2,4} , 1) = min {c32 + g( 2, 4 ,1) , c34 + g( 4, 2 ,1) }
When |S| = 2
= min { (13 + 18) , (12 + 13) } = 25
g( 4 , {2,3} , 1) = min {c42 + g( 2, 3 ,1) , c43 + g( 3, 2 ,1) }
= min { (8 + 15) , (9 + 18) } = 23
23 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 32
When |S| = 3
g( 1 , {2,3,4} , 1) = min {(c12 + g( 2,{3,4} ,1)), (c13 + g( 3, {2,4} ,1) , (c14 + g( 4, {2,3} ,1) }
= min {( 10+ 25), (15 + 25) , (20 + 23) }
= min {35, 40 , 43 } = 35
The optimal solution is 35
1– 2 – 4 – 3 – 1
10 9
10
1 2 4 3
23 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 33
OPTIMAL BINARY SEARCH TREES
A Binary Search Tree is a tree where the key values are stored in the internal nodes. The
external nodes are null nodes.
For each internal node all the keys in the left sub-tree are less than the keys in the node,
and all the keys in the right sub-tree are greater the keys in the node.
24 March 2021,09:00-10:50 A.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 34
Two Binary Search Trees (BST)
1 1
10 10
2 2 2 2
5 25 5 20
3 3 3
20 15 25
4
15
• For each identifier with equal searching probability , average number of comparisons for a successful
search:
• probability(5, 10, 15, 20, 25) = (0.3, 0.3, 0.05, 0.05, 0.3)
E = 2 + 2 + 4 + 4 + 3 + 2 = 17
24 March 2021,09:00-10:50 A.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 36
In the binary search tree( BST):
Let assume that the set of Identifiers is a1, a2, …, an with a1 < a2 < … < an
1
pi : probability of successful search for ai
10
qi : probability of unsuccessful
n
search
n
ai < x < ai+1 2 2
p q 1
i i
3
5
3
25
3
i 1 i 0 3
Total cost 20
n n 4 4
p level (a ) q (level (failure node i) 1)
i i i 15
i 1 i 0 5 5
An optimal binary search tree for a1, …, an is the one that minimizes the total cost.
24 March 2021,09:00-10:50 A.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 37
Cost(l)= ∑1≤i≤k-1 pi * level(ai) + ∑0≤i≤k-1 qi * (level (Ei)-1)
24 March 2021,09:00-10:50 A.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 38
ak
L R
1≤k≤n
c(0,n) = min{c(0,k-1) + c(k,n) + p(k) + w(0,k-1) + w(k,n)
i<k≤j
c(i,j) = min{c(i,k-1) + c(k,j) + p(k) + w(i,k-1) + w(k,j) }
i<k≤j
24 March 2021,09:00-10:50 A.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 39
c(i,j) = min{c(i,k-1) + c(k,j)} + w(i,j)
Let n = 4 and (a1, a2, a3, a4) = (do, if, int, while).
q(0:4)=(q0, q1, q2, q3, q4) = (2, 3, 1, 1, 1). Construct OBST (T04 ) 2
0 1 i 3 4
Sol: Initially w(i , i)=q(i) , c(i , i) = 0 and r( i , i )=0 w00=2 w11=3 w22=1 w33=1 w44=1
0 c00=0 c11=0 c22=0 c33=0 c44=0
w(0 , 0) = q(0)=2 w(3 , 3) = q(3)=1 r00=0 r11=0 r22=0 r33=0 r44=0
c(0 , 0) = 0 c(3 , 3) = 0 w01=8 w12=7 w23=3 w34=3
r(0 , 0) = 0 r(3 , 3) = 0 1 c01=8 c12=7 c23=3 c34=3
|j-i| r01=1 r12=2 r23=3 r34=4
w02=12 w13=9 w24=5
w(1 , 1) = q(1)=3 w(4 , 4) = q(4)=1 2 c02=19 c13=12 c24=8
c(1 , 1) = 0 c(4 , 4) = 0 r02=1 r13=2 r24=3
r(1 , 1) = 0 r(4 , 4) = 0 w03=14 w14=11
3 c03=25 c14=19
r03=2 r14=2
w(2 , 2) = q(2)=1 w04=16
c(2 , 2) = 0 4 c04=32
r(2 , 2) = 0 r04=2
24 March 2021,09:00-10:50 A.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 40
w(i,j) = w(i,j-1)+p(j)+q(j)
|j-i|=1 c(i,j) = min{c(i,k-1) + c(k,j)} + w(i,j)
i<k≤j
r(i,j) = k
w(0 , 1) = w(0,0) +p(1) + q(1)
= 2 + 3 + 3 =8 0 1 2 3 4
w00=2 w11=3 w22=1 w33=1 w44=1
c(0 , 1) = min{c(0,1-1) + c(1,1)} + w(0,1)
0 c00=0 c11=0 c22=0 c33=0 c44=0
0<k≤1
r00=0 r11=0 r22=0 r33=0 r44=0
= 0+0+8=8 w01=8 w12=7 w23=3 w34=3
r(0 , 1) = 1 1 c01=8 c12=7 c23=3 c34=3
w(1 , 2) = w(1,2-1) +p(2) + q(2) r01=1 r12=2 r23=3 r34=4
w02=12 w13=9 w24=5
= w(1,1) +p(2) + q(2)
2 c02=19 c13=12 c24=8
= 3 + 3 + 1 =7
r02=1 r13=2 r24=3
c(1 , 2) = min{c(1,2-1) + c(2,2)} + w(1,2) w03=14 w14=11
1<k≤2 c03=25 c14=19
3
= 0+0+7=7 r03=2 r14=2
r(1 , 2) = 2 w04=16 w(3 , 4) = w(3,4-1) +p(4) + q(4)
4 c04=32
w(2 , 3) = w(2,3-1) +p(3) + q(3) = w(3,3) +p(4) + q(4)
r04=2 = 1 + 1 + 1 =3
= w(2,2) +p(3) + q(3)
= 1 + 1 + 1 =3 c(3 , 4) = min{c(3,4-1) + c(4,4) }+ w(3,4)
c(2 , 3) = min{c(2,3-1) + c(3,3)} + w(2,3) 3<k≤4
2<k≤3 = 0+0+3=3
= 0+0+3=3 r(3 , 4) = 4
r(2 , 3) = 3
24 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 41
w(0 , 2) = w(0,2-1) +p(2) + q(2) |j-i|=2
= w(0,1) +p(2) + q(2)
= 8 + 3 + 1 =12
c(0 , 2) = min{(c(0,1-1) + c(1,2)) , (c(0,2-1) + c(2,2))} + w(0,2)
0<k≤2 K=1 K=2
= min{(c(0,0)+c(1,2)) ,(c(0,1)+c(2,2))}+w(0,2)
0 1 2 3 4
= min{(0+7),(8+0)}+12=7+12=19 w00=2 w11=3 w22=1 w33=1 w44=1
r(0 , 2) = 1 c00=0 c11=0 c22=0 c33=0 c44=0
0
w(1 , 3) = w(1,3-1) +p(3) + q(3) r00=0 r11=0 r22=0 r33=0 r44=0
= w(1,2) +p(3) + q(3) w01=8 w12=7 w23=3 w34=3
= 7 + 1 + 1 =9 1 c01=8 c12=7 c23=3 c34=3
c(1 , 3) = min{(c(1,2-1) + c(2,3)) , (c(1,3-1) + c(3,3))} + w(1,3) r01=1 r12=2 r23=3 r34=4
1<k≤3 K=2 K=3 w02=12 w13=9 w24=5
2 c02=19 c13=12 c24=8
= min{(c(1,1)+c(2,3)) ,(c(1,2)+c(3,3))}+w(1,3)
r02=1 r13=2 r24=3
= min{(0+3),(7+0)}+12=3+9=12 w03=14 w14=11
r(1 , 3) = 2 c03=25 c14=19
w(2 , 4) = w(2,4-1) +p(4) + q(4) 3
r03=2 r14=2
= w(2,3) +p(4) + q(4) w04=16
= 3 + 1 + 1 =5 4 c04=32
c(2 , 4) = min{(c(2,3-1) + c(3,4)) , (c(2,4-1) + c(4,4))} + w(2,4) r04=2
2<k≤4 K=3 K=4
= min{(c(2,2)+c(3,4)) ,(c(2,3)+c(4,4))}+w(2,4)
= min{(0+3),(3+0)}+5=3+5=8
r(2 , 4) = 3
24 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 42
|j-i|=3
24 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 43
|j-i|=4
0 1 2 3 4
r[ i , k-1 ] r[ k , j ]
w00=2 w11=3 w22=1 w33=1 w44=1
do int c00=0 c11=0 c22=0 c33=0 c44=0
0
r00=0 r11=0 r22=0 r33=0 r44=0
r[ 0 , 4 ] = 2 w01=8 w12=7 w23=3 w34=3
1 c01=8 c12=7 c23=3 c34=3
while
r01=1 r12=2 r23=3 r34=4
w02=12 w13=9 w24=5
r[ 0 , 1 ] = 1 r[ 2 , 4 ] = 3 2 c02=19 c13=12 c24=8
r02=1 r13=2 r24=3
w03=14 w14=11
r[0,0]= 0 r[1,1]= 0 3 c03=25 c14=19
r03=2 r14=2
r[ 2 , 2 ] = 0 r[ 3 , 4 ] = 4
w04=16
4 c04=32
r04=2
r[ 3 , 3 ] = 0 r[ 4 , 4 ] = 0
24 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 45
Algorithm OBST(p,q,n)
// Given n distinct identifiers a1 < a2 < … < an, and probabilities
// p[i], 1 ≤ i ≤ n, and q[i], 0 ≤ i ≤ n this algorithm computes
//the cost c[i,j] of optimal binary search trees Tij
// for identifiers ai+1, …, aj. It also computes r[i,j] , the root of Tij.
2. Design a three stage system with device types D1 , D2 , D3 . The cost are $20 , $ 25 , $ 35
respectively. The cost of the system is to be no more than $175. The reliability of each device type is
0.8 , 0.7 , 0.4 respectively.
24 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 48
THANK YOU
24 March 2021,02:00-02:50 P.M Department of CSE, GIT Course Code and Title:19ECS234 and DESIGN AND ANALYSIS OF ALGORITHMS GVSN 49