summaryrefslogtreecommitdiff
path: root/37/CH8/EX8.6/s6.sci
blob: 72e5126c7938d57edadbc88289988481c384901f (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
//Depth First Search Traversal
funcprot(0)
function[]=Dfs(adj,n);
  i=1,j=1;
  colour=[];
  for i=1:n
  for j=1:n
      colour=[colour(:,:) 0];
    end
  end
  disp("The DFS traversal is");
dfs(adj,colour,1,n);  
endfunction
function[]=dfs(adj,colour,r,n)
  colour(r)=1;
  disp(r,"  ");
  for i=1:n
    if(adj((r-1)*n+i)&(colour(i)==0))
      dfs(adj,colour,i,n);
    end
  end
  colour(r)=2;
endfunction
//Calling Routine:
n=4;
adj=[0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 0]
Dfs(adj,n)