diff options
Diffstat (limited to '1034/CH6/EX6.1/6s1.sce')
-rwxr-xr-x | 1034/CH6/EX6.1/6s1.sce | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/1034/CH6/EX6.1/6s1.sce b/1034/CH6/EX6.1/6s1.sce new file mode 100755 index 000000000..ec3821385 --- /dev/null +++ b/1034/CH6/EX6.1/6s1.sce @@ -0,0 +1,30 @@ +clear;
+clc;
+disp("Example 6.1");
+//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)
\ No newline at end of file |