Say I have an adjacency matrix
boolean[][] adjMatrix = [n][n]
and I want a function that returns a boolean[] of all the connected components of a given vertex.
public static boolean[] connected(boolean[][] aMatrix, int vertexCount, int givenVertex){
boolean[] connections = [vertexCount]
connections[givenVertex] = true;
for(int i = 0; i < vertexCount, i++){
If(...) connections[i] = true;
...
}
return connections;
}
For example on this graph
connected(adjMatrix, 6, 0)
//returns [true, true, false, false, true, true, false]
I've been working on this for a while, and I think I need to use Breadth First Search or Depth First Search, but I am still kind of confused on using them.