Thursday 24 April 2014

Wap to check the presence of pendant edges in a Graph using adjacency matrix

The adjacency matrix consists of "0" and "1" where 0 refers edges not connected directly and 1 refers edges connected directly on the given graph. The input provided as matrix formate where have to take care of rows and column of specific graph. An edge connecting a leaf is called pendent edge hence we add the counter "count2" while traversing graph a[i][j] if (a[i][j]==1) then add count. At last if we found count2==1 then say pendent edge found or else say not found.

 #include<stdio.h>  
 #include<conio.h>  
 void main()  
 {  
  int i,j;  
  int count2;  
  int m,n,a[10][10];  
  clrscr();  
  printf("\n @@@ Enter the no of edge and vertice @@@ \n-> ");  
  scanf ("%d%d",&m,&n);  
  printf ("\n Enter the adjacency matrix : \n");  
  for (i=0;i<m;i++)  
  {  
   for(j=0;j<n;j++)  
      {  
       scanf("%d",&a[i][j]);  
      }  
  }  
 for (i=0;i<m;i++)  
  {  
   count2=0;  
    for (j=0;j<m;j++)  
    {  
      if(a[i][j]==1)  
      {  
       count2=count2+1;  
      }  
    }  
      if (count2==1)  
      {  
           printf ("\n>>>Pendent edge found = %d\n",i+1);  
      }  
      else  
      {  
      printf (" \n no pendent edge found = %d",i+1);  
      }  
  }  
  getch();  
  }  
 




No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2022