summaryrefslogtreecommitdiff
path: root/1034/CH6/EX6.3/6s3.sce
blob: 15cd9748bc19c676f47060ca0e3371748ffca43b (plain)
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
30
31
32
33
34
clear;
clc;
disp("Example 6.3");
//Warshall's Algorithm
clc;
clear;
funcprot(0)
function[path]=transclose(adj,n)
  for  i=1:n
    for j=1:n
      path((i-1)*n+j)=adj((i-1)*n+j);
    end
  end
  for k=1:n
    for  i=1:n
      if(path((i-1)*n+k)==1)
        for j=1:n
          path((i-1)*n+j)=path((i-1)*n+j)|path((k-1)*n+j);
        end
      end
    end
  end
  printf("Transitive closure for the given graph is:\n");
  for  i=1:n
    printf("For vertex %d \n",i);
    for j=1:n
       printf("%d %d is %d\n",i,j,path((i-1)*n+j));
    end
  end
endfunction
//Calling Routine:
n=3;
adj=[0 1 0 0 0 1 0 0 0]
path=transclose(adj,n)