Professional Documents
Culture Documents
Let ri be the reliability of device D i. Then the reliability of entire system is ri. Even the
reliability of individual device is good the reliability of entire system is not good.
Example: If n = 10, ri = 99
D1 D2 D3
ri = 0.904
It stage i contains mi copies of device Di then the probability that all m i have a
malfunction is (1 – ri)mi
Hence reliability of stage i is 1 – (1 – ri)mi
Device duplication is to maximize reliability. This maximization is carried under a cost
constraint.
If ci is the cost of device i and C is maximum allowable cost.
mi) must be maximum.
Design a 3 stage system with devices types D 1, D2, D3. The costs and reliabilities of the
devices are 30, 15, 20 and 0.9, 0.8, 0.5 respectively. Maximum number of devices
available are Di = 2, D2 = 3 and D3 = 3. The cost of system must not exceed
Solution:
If stage i has mi devices of type i in parallel then I (mi) = 1 – (1 – ri)mi
Let Sji represent all types of obtainable from Si – 1 by choosing mi = j
S12 = {0.9, 30}
S21 = {(0.9, 30); (0.99, 0.60)}
S12 = {(0.72, 45); (0.792, 75)}
S22 = {(0.864, 60); (0.9504, 90)}
The triple (0.9504, 90) is eliminated since we cannot insert D 3
S32 = {(0.8928, 75)}
S2 = {(0.72, 45), (0.864, 60), (0.8928, 75)}
S13 = {(0.36, 65), (0.432, 80), (0.4464, 95)}
S23 = {(0.54, 85), (0.648, 100)}
S33 = {(0.63, 105)}
S3 = {(0.36, 65), (0.432, 80), (0.54, 85), (0.648, 100)}
The best design has a reliability of 0.648 and cost of 100
m1 = 1, m2 = 2 and m3 = 2
43
Where I is reliability of stage i. Once a value m n has choosen the remaining decisions
must be such that to use remaining funds in C – C nmn an optimal way. We can
generalize that for any (Fi(x) = max 1 mi ui {I(mi)fi – 1(c – cimi)}
Example:
Design a three sage system with device types D1, D2, D3. The costs and reliabilities of
the devices are 30, 15, 20 and 0.9, 0.8, 0.5 respectively. Maximum number of devices
available are D1 = 2, D2 = n3, and D3 = 3.
Solution: Sji represents all tuples
S11 = {(0.9, 30)}
S21 = {(0.9, 30), (0.99, 60)}
S12 = {(0.72, 45), (0.792, 75)}
S22 = {(0.864, 60)}
S32 = {(0.8928, 75)}
Let G = (V, E) be a directed graph with n vertices. Let c be a cost adjacency matrix for G
such that c(i, i) = 0 and c(i, j), is the length of edge (i, j) if < i, j > E and C(i, j) = if <i,
j> E. The all pairs shortest path problem is to determine a matrix a such that A(i, j) is
the length of shortest path form i to j.
The solution for the problem can be obtained from
Ak (i, j) = min{Ak-1(i, j), Ak-1(i, k) + Ak-1(k, j)}
Where Ak(i, j) is length of shortest path from i to j.
Algorithm:
For I 1 to n
{
for j 1 to n
{
A(i, j) cost(i, j)
}
}
For k 1 to n
{
For I 1 to n
{
44
For J 1 to n
A(i, j) = min{A(i, j), (A(i, k) + A(k, j)}
}
}
Example: Let us consider the graph whose cost matrix is shown.
1 2 3
1 - 4 11
A(0)
2 6 - 2
3 3 1
1 2 3
A(1) 1 - 4 11
2 6 - 2
3 3 7 -
1 2 3
A(2) 1 - 4 6
2 6 - 2
3 3 7 0
(1, 1) = (2, 3) + (3, 1)
Cij > 0 for all I and j if (I, j) E cij = if (I, j) E. A tour of G is a directed cycle that
includes every vertex in V. The cost of tour is the sum of the cose of edges on the tour
and must be minimum.
Let us assume the tour starts from vertex 1 and ends at vertex1. Every tour consists of an
edge (1, k) for some k v – {1}. The path from k to 1 goes through each vertex v – {1, k}.
45
Let g(i, s) be the length of shortest path starting from i going through verties in s and
terminating at vertex 1.
g(1, v – {1}) = min{c1k + g9k, v – [1, k})
Where v is total number of vertices.
In general.
g(i, s) = min(cij + g(j, s – {j})
where S = v – {I}
Example: Let us consider a graph with five nodes. Cost matrix of the graph is given
below.
1 2 3 4 5
1 - 10 15 20 15
2 5 - 9 10 15
3 6 13 - 12 7
4 8 8 9 - 4
5 2 5 7 10 -
Solution:
When |s| =
g(2, ) = c21 = 5
g(3, ) = c31 = 6
g(4, ) = c41 = 8
g(5, ) = c51 = 2
When |s| = 1
46
g(5, {2}) = 10 = c52 + g(2, ) = 5 + 5
g(5, {3}) = 13 = c53 + g(3, ) = 7 + 6
g(5, {4}) = 18 = c54 + g(4, ) = 10 + 8
When |s| = 2
When |s| = 4
47
#####
48
Time complexity
49
E0 contains identifier X < a1
E1 contains identifier a1 < X < a2
E1 contains identifier a1 < X < ai + 1
If a failure node for Ei is at level 1 then only 1 – 1 iterations are made.
Cost of failure node is
Q(i)*(level(Ei) – I)
Cost of binary search tree = p(i)*level(ai) + Q(i)*(level(Ei – l)
Where P(i) is probability of successful search
Q(i) is probability of unsuccessful search
Example: Find OBST for a set (a1, a2, a3) = (do, if, stop) if p(1) = 0.5, P(2) = 0.1, P(3) =
0.05 and q(0) = 0.15, q(1) = 0.1, q(2) = 0.05, q(3) = 0.05
The possible binary search trees are
Cost(tree b):
Cost(tree c):
Cost(tree d):
Cost(tree e):
51
= 14 + MIN{8 + 0) or {0 + 7} = 12 + 7 = 19
w(2, 4) = w(2, 4) + min{c(2, 3) + c(3, 4) = 6 or c(2, 2) + (3, 4) = 3} = 8
w(1, 3) = P(3) + P(3) + W(1, 2) = 2 + 7 = 9
C(1, 3) = W(1, 3) + min{C(1, 1) + C(2, 3) = 3 or C(1, 2) + C(3, 3) = 7} = 12
R(1, 3) = 2
W(0, 3) = P(3) + Q(3) + w(0, 2) = 14
C(0, 3) = w(0, 3) + min{c(0, 1) + c(2, 3)
C(0, 2) + c(3, 3)}
= 14 + min????
= 25
First solve all c(i, j) such that j – I = 1 next compute c(I, j) such that j – 1 = 2 and so on
during the computation record R(I, j) root of tree T ij. By observation we have w(I, j) = P(j)
+ Q(j) + W(i, j – 1)
Row Col
0 1 2 3 4
0 2, 0, 0 3, 0, 0 1, 0, 0 1, 0, 0 1, 0, 0
j-i=1 8, 8, 1 7, 7, 2 3, 3, 3 3, 3, 4
4 16, 32, 2
C(0, 4) = 32 is minimum
The tree with root as 2 node is OBST.
Algorithm:
Procedure OBST(P, Q, n)
{Real P(1 : n), Q(O : n), C(O : n, O : n),
W(O : n, O : n)
Int R(O : n, O : n)
For I = 0 to n – 1
{
{w(i, i), R(i, i), c(i, i) (Q(i), 0, 0)
(W(i, i + 1), R(i, i + 1), c(i, i +1) (Q(i) + Q(i +1) + P(i +1), i + 1, Q(i) + Q(i +1) + P(i +1)
52
}
(w(n, n), R(n, n), C(n, n) Q(n), 0, 0)
For m : 2 to n
{
For İ : 0 to n – m
{
j+i +m
w(i, j) = W(i, j – 1) + P(j) + Q(i)
k=l
where R(i, j – 1) 1 R(i +1, j) that minimize c(i, j)
C(i, j) = w(i, j) + c(İ, k – 1) + c(k, j)
R(i, j) = k
}
}
Time Complexity:
####
53
BASIC SEARCH AND TRAVERSAL TECHNIQUES
The solution of many problems involves the manipulation of trees and graphs.
The manipulation requires to search an object in a tree or graph by
systematically examining their vertices according to a given property. When
searching involves examines every vertex then it is called traversal.
Tree traversals:
Tree: A tree is a finite set of one or level
A 1
more nodes such that there is a
special node called root and
B C D 2
remaining are partitioned into n
E F H I J
0 disjoint sets T 1, ………T n where 3
G
each of these sets called as sub K L M 4
trees.
Binary Tree Traversals: If we let L, D, R stand for moving left, printing data and
moving right, there are six possible combinations of traversals
LDR, LRD, DLR, DRL, RDL and RLD.
If we adopt a convention that we traverse left before right, then we have only 3
traversals.
LDR, LRD and DLR
Inorder Traversal (LDR):
Moving down the tree towards left until you cannot go further, then print the data
at that node and move on to right and continue.
A
If you cannot move to right and continue. If you C
B
cannot move to right go back one more node
D E
Example:
F G
In order Traversal for the tree is
FDHGIBEAC H I
55
Call INORDER(LCHILD(T))
______ Call PRINT(T)
______ Call INORDER(RCHILD(T))
}
}
For the example shown in previous slide algorithm works as shown here
Call of INORDER Value in root Action
Main A
1 B
2 D
3 F
4 - Print F
4 - Print D
3 G
4 H
5 - Print H
5 - Print G
4 1
5 - Print I
5 - Print B
2 E
3 - Print E
3 - Print A
1 C
2 - Print C
2 -
POSTORDER TRAVERSAL(LRD): H I
Procedure POSTORDER(T)
{
If (T1 = 0)
{
57
then call POSTORDER(LCHILD(T))
call POSTORDER9RCHILD(T))
call PRINT(T) A
} B C
}
D E
Example:
F G
The post order traversal of the tree shown is
H I
FHIGDEBCA
#####
58