Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

24 Jan 2013

Algorithm for GRAPH

Q.) Write a ALGORITHM to show whether the GRAPH  is Connected or Not. 

Sol)

# Comp( Graph )
{
    For each vertex v belongs to Vertices[Graph]
        {
             make-set(v)
         }
   For each edge (u,v) belongs to Edges[Graph]
         {
              if(find-set(u) not equal to find-set(v))
                  {
                       Union(u,v)
                  }
         }

}

Connected-Comp(u,v)
{
      if (find-set(u)=find-set(v))
           {
                print "CONNECTED"
            }
      else
                print "NOT CONNECTED"
}

No comments:

Post a Comment