1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
clear;
clc;
disp("Example 6.5");
//Finding The Number Of Simple Paths From One Point To Another In A Given Graph
funcprot(0)
function[]=sim_path(n,adj,i,j);
l=0;
m=1;
for m=1:n
l=l+path(m,n,adj,i,j);
end
printf("There are %d simple paths from %d to %d in the given graph\n",l,i,j);
endfunction
function[b]=path(k,n,adj,i,j)
b=0;
if(k==1)
b=adj((i-1)*n+j);
else
for c=1:n
if(adj((i-1)*n+c)==1)
b=b+path(k-1,n,adj,c,j);
end
end
end
return b;
endfunction
n=3;
adj=[0 1 1 0 0 1 0 0 0];
b=sim_path(n,adj,1,3)
|