Reputation: 162
I have this adjacency matrix :
And I don't know if I can check if any of the nodes are not connected with the others. I mean, if it's alone, a row and column of zeros (for example, the first one, A
,) should return false because simple connectivity does not exist.
public bool HayConectividadsimple()
{
bool respuesta = true;
for (int i = 0; i < Aristas.GetLength(0); i++)
{
for (int j = 0; j < Aristas.GetLength(1); j++)
{
if (i, j == 0)
return false;
}
}
return respuesta;
}
Hope you can help me.
Best regards,
Upvotes: 2
Views: 1074
Reputation: 3789
From my understanding you're looking for a whole row of 0 and a whole column of 0. If you spot either then return false. Roughly something like this:
For each node..
Return true otherwise.
So, that looks like this:
public bool HayConectividadsimple()
{
// For each node..
for (int i = 0; i < Aristas.GetLength(0); i++)
{
// Assume it's not connected unless shown otherwise.
bool nodeIsConnected=false;
// Check the column and row at the same time:
for (int j = 0; j < Aristas.GetLength(1); j++)
{
if (Aristas[i, j] != 0 || Aristas[j, i] != 0)
{
// It was non-zero; must have at least one connection.
nodeIsConnected=true;
break;
}
}
// Is the current node connected?
if(!nodeIsConnected)
{
return false;
}
}
// All ok otherwise:
return true;
}
Upvotes: 1