How we can find Shortest path between two vertex in a weighted directed acyclic graph that has positive and negative weight. in O(|V|+|E|)?
thanks to all.
How we can find Shortest path between two vertex in a weighted directed acyclic graph that has positive and negative weight. in O(|V|+|E|)?
thanks to all.
Copyright © 2021 JogjaFile Inc.
First perform a DFS to remove all the vertex that are not accessible from the source.
Then apply the same idea as Dijkstra's algorithm:
Why it works: when you push a vertex you are sure that you found the shortest distance to it.
Why it is in $O(E+V)$ because each time you use an edge you remove it.
I hope it helps.