Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C, 1. (10 pts) Implement a function that determines if there exist a route be

ID: 3716951 • Letter: I

Question

In C,

1. (10 pts) Implement a function that determines if there exist a route between two nodes in an undirected graph. The graph will be represented with its adjacency matrix which for this problem is a binary 2D matrix. For instance, the graph shown in Fig. 1 has the following adjacency matrix: 1 1 0 01 0 1 0 1 01 0 0 1 01 0 0 0 0 1 01 1 0 0 01 0 0 where G(6141 means that we can reach node 4 from node 6, and G[6][1]0 means that we cannot reach node 1 from node 6. Your function will return TRUE if there is a path from node 6 to node 1 which in this case there is at least one: 6-4- 5 1, and return FALSE otherwise. Your function must have the following signature: int IsThereAPath (const int**adjacency_matrix, const int num_nodes, const int source, const int destination);

Explanation / Answer

CODE:

//Please ask any doubts in the comments, and rate the answer if you fins it helpful

bool isThereAPath(const int** graph, int V, int s, int d)

{

if (s == d)

return true;

bool *visited = new bool[V];

for (int i = 0; i < V; i++)

visited[i] = false;

queue<int> q;

visited[s] = true;

q.push(s);

while (!q.empty())

{

s = q.front();

q.pop();

for (int i = 0; i < V; i++)

{

if (graph[s][d] == 1)

return true;

if (graph[s][i] == 1 && !visited[i])

{

visited[i] = true; q.push(i);

}

}

}

return false;

}