Question

Explain how to use depth first search to find Transitive closure

Explain how to use depth first search to find Transitive closure
0 0
Add a comment Improve this question Transcribed image text
Answer #1

For a given directed graph, if the vertex v is reachable from another vertex u for all vertex pair (u,v) in the above given graph then we mark 1 in the reachability matrix in the position (u,v). Otherwise it is marked 0.

The idea of finding transitive closure using DFS is simple. We call DFS from every vertex u of the graph and check which vertices v are reachable from u. And mark the position (u,v) as 1 if reachable.

The asymptotic complexity of the DFS is if we are using adjacency matrix, where is the total number of vertices in the directed graph. So the complexity of using transitive closure is . The reason is DFS is called for every vertex present. So .

But if we are running DFS using recursive approach then there is a modification we can apply and decrease the computation time. We would not call for DFS for an adjacent vertex if it has already been reach by some other vertex.

Consider the above case. We first apply DFS on vertex A. We reach vertex B from there and mark the position (A,B) as 1.

After that we run DFS on B. We reach vertex C. After that we modify the location (A,C) as 1. But note that here we already know we can reach vertex C from B. We can also modify the location (B,C) as 1. Now we run DFS on vertex C and not finding any adjacent nodes we can move back to B. Then move to vertex D. Similarly we can mark both (A,D) and (B,D) as 1.

We can reduce the complexity using this approach to as we are travelling each edge just once. The same approach can be done for iterative DFS.

Add a comment
Know the answer?
Add Answer to:
Explain how to use depth first search to find Transitive closure
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT