Graph is connected or not ! in c language for ford fulkersion

95 views Asked by At

// i created this as a part of ford fulkersion algorithm

#include<stdio.h>
#include<conio.h>

void main()
{
    int v,i,e,ch[20],sv[20],count=0,s,j;
    clrscr();
    printf("Enter No of vertices :");
    scanf("%d",&v);
    for(i=1;i<=v;i++)
    {
        printf("Enter vertices %d",i);
        scanf("%d",&sv[i]);
    }
    printf("Enter starting node : ");
    scanf("%d",&s);

//Problem in this below loop(logic is not working ) if any one have solution please help !

    for(i=s;i<=v-1;i++)
    {
        for(j=i+1;j<=v;j++)
        {
            printf("conn betn %d and %d",i,j);
            scanf("%d",&ch[i]);
            if(ch[i]!=1)
            {
                break;
            }
            else if(ch[i]==1)
            {
                count++;
            }
        }
    }

//----------------------------------------------------------

if(count>=v)
{
    printf("Graph is connected");
}
else
{
    printf("Graph is disconnected");
}
getch();

}

1

There are 1 answers

0
Juan Lopes On BEST ANSWER

Your algorithm is wrong. You are assuming that if you have at least v edges, your graph is connected. But if you have a graph like this, with 6 nodes and 6 edges, it is still not connected:

enter image description here