Thursday, January 2, 2014

DFS (depth first search)

DFS is another search algorithm in graphs. The absic use os this algorithm is finding the "first" way between to edges. It won't be the shortest like BFS. but it will find the first way betwwen 2 nodes. We implement DFS with the help of recursion.
void DFS(int X)
{
    for(i=0;i< number of neighbours of X ; i++)
  {  
     a=current neighbour;
     if( not marked a)
       {    
             DFS(a);
            a becomes marked;
       }
    }
}

        

No comments:

Post a Comment