Tuesday, 26 June 2012

CLASSIFIACTION OF EDGES IN GRAPH 
EDGES OF A DIRECTED GRAPH CAN BE DIVIDE INTO FOUR GROUPS 
1.Tree Edge 
2.Back Edge 
3.Forward Edge 
4.Cross Edge                



TREE EDGE :
an edge included in the DFS spanning forest.
BACK EDGE :
an edge to a vertex to its spanning tree ancestor.  
FORWARD EDGE :
an edge from a vertex to a spanning tree non son descendant.
CROSS EDGE :
an edge between two vertices is a cross edge when there is no ancestor and descendant relationship between them in spanning forest.


code to identify the edges
static int time=0;
void DFS(int v)
{
int i;
time++;
d[v]=time;
state[v]=visited;
for(i=0;i<n;i++)
{
     if(adj[v][i]==1)
       {
          if(state[i]==initial)
              {
              cout<<"Tree Edge :"<<v<<" "<<i<<"\n";
              DFS(i);
               }
            else if(state[i]==visited)
               { 
                   cout<<"Back Edge :"<<v<<" "<<i<<"\n";    
                }
              else if(d[v]<d[i])
                  cout<<"Forward Edge :"<<v<<" "<<i<<"\n";
                else
                  cout<<"Cross Edge :"<<v" "<<i<<"\n";
              }
     }
state[v]=finished;
  f[v]=++time;
return ;
}

No comments:

Post a Comment