wiz-icon
MyQuestionIcon
MyQuestionIcon
2
You visited us 2 times! Enjoying our articles? Unlock Full Access!
Question

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 form 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 (i <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”);

Choose the correct expression for E3

A
(A[i] [j] && !A[j] [i])
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
(!A[i] [j] A[j] [i])
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
(A[i] [j] && !A[j] [i])
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
(A[i] [j] !A[j] [i])
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
Open in App
Solution

The correct option is D (A[i] [j] !A[j] [i])
In this program initially flag is set to 1 i.e. assume sink is present in the graph.

And by using For loop if flag is reset to 0 then sink is not present otherwise sink is present.

For loop will set flag = 0 if the column entries are all 1 for sink (vertex) and the entries for row is all 0.

If we look at above diagram for vertex 'd', i =3 and j = 0.

So while ((j! = i) && (A[3] [0]!A[0][3])
True && (0!1))
True && false = false, so flag not set to 0.

Then while ((j! = j)&& (A[3][1]!A[1] [3])
True && false = false, so flag not set to 0.

Try for other vertex we will set flag = 0 i.e. not exist sink.

Like this for vertex d flag will not set to 0 i.e. sink exist.

flag
Suggest Corrections
thumbs-up
0
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon