Question

You are given an unweighted DAG (Directed Acyclic Graph) G, along with a start node s and a target node t. Design a linear ti

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Single source shortest distances in O(V+E) time for DAG (Directed Acyclic Graph). The idea is to use Topological Sorting.

Algorithm :

1. Initialize dist[] = {INF, INF, ….} and dist[s] = 0 where s is the source vertex.
2. Create a toplogical order of all vertices.
3. Do following for every vertex u in topological order.
Do following for every adjacent vertex v of u

if (dist[v] > dist[u] + weight(u, v))

dist[v] = dist[u] + weight(u, v)

Time Complexity: Time complexity of topological sorting is O(V+E). After finding topological order, the algorithm process all vertices and for every vertex, it runs a loop for all adjacent vertices. Total adjacent vertices in a graph is O(E). So the inner loop runs O(V+E) times. Therefore, overall time complexity of this algorithm is O(V+E).

Add a comment
Know the answer?
Add Answer to:
You are given an unweighted DAG (Directed Acyclic Graph) G, along with a start node s...
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
ADVERTISEMENT