Warshall's Algorithm (ADA Lab)
Warshall's Algorithm (ADA Lab)
dynamie prmgranming
The branAitive Can be
cloßure of a digraph with n verices
defined by n boolen mtrix in uhich the element mth
(th yow
where' osísn and jtheotumn osi<n is 5
there is a tmvial
tivial path from ith vertex to h vertex,
otherwike it D
Algerithm Warshal
7 input i Adjaceny matix of
Houtput : Transitive digraph
closure of digraph
Ro) A
for k: 1 to n do
for iz 4 to n do
tor í= 1 to n do
Ck-) (k-)
(R Ci,kJ and R CK,iJ)
reurn Ro)
Trating p mabik
A
1
Initalize the
K= No.o Intermediate vertices
2 2
K= o
R
(ab) =1 (6,d)=1
() ’(a,d)-1
R
(6,d)= 1
(2)
R
No pair
c d
)
>(6,4):/
(6,d)=1 with ( d,a):)
(d,)=/->():)
Cdd 1 with
(4)
R
b
d
Proqyam
#include < stdioihs
(int p[][o1 int n)
Vofd warshall
int i,j,kj
tor ( k=l j k<=nj ktt)
<njitt)
foy ( (2 1 ,
(i-1; iKenj j+t) PCKJLJJ
for [J[k]4f
PLiJLD- PLIJJliJI|P
3
int main()