retagged by
1,236 views
5 votes
5 votes

Source of the question - here

A sink in a directed graph is a vertex i such that there is an edge from every vertex $j ≠ i $ to i and there is no edge from i to any other vertex. A directed graph G with n vertices is represented by its adjacency matrix A, where $A[i] [j] = 1$ if there is an edge directed from vertex i to j and 0 otherwise. The following algorithm determines whether there is a sink in the graph G.

i = 0
do {
    j = i + 1;
    while ((j < n) && E1) 
       j++;
    if (j < n) E2;
} while (j < n);

flag = 1;
for (j = 0; j < n; j++)
    if ((j! = i) && E3)
        flag = 0;

if (flag)
    printf("Sink exists");
else
    printf ("Sink does not exist");

 

Correct Answer is - E1: ! A[i][j] and E2: i=j;

Can someone explain how E2 = i=j. 

i=j means we are looking for diagonal elements. So, how do we look for them as a sink as all the diagonal elements in adjacency matrix is = 0. You can take a Graph with 4 vertices and make anyone of them as a sink.

retagged by

1 Answer

Best answer
23 votes
23 votes

Answer

 

selected by

Related questions

0 votes
0 votes
0 answers
4