Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Find the shortest paths from a source in a Directed Acyclic Graph in O(V + E). By relaxing edges in topological order, we guarantee that each node's shortest path is finalized in a single pass.
Processing nodes in topological order ensures that when we relax edges from node u, its own shortest path distance is already finalized.
Unlike Dijkstra's, this algorithm doesn't need a priority queue. It simply visits each node and its outgoing edges once, making it optimal for DAGs.