Download presentation
Presentation is loading. Please wait.
1
SINGLE-SOURCE SHORTEST PATHS IN DAGs
NAVEEN DOKKU NIRMITH SUDEV VELAGALETI
2
Shortest Path in Directed Acyclic Graph
We just find the shortest paths from given source to all other vertices if a source vertex is given in the graph.
3
2.1 We initialize distances to all vertices as infinite and distance to source as 0, then we find a topological sorting of the graph. Topological Sorting of a graph represents a linear ordering of the graph. The sample process: First find all vertices of Graph. Ascending sort all vertices of Graph. (Topological ordering) Loop for length of vertices of graph. Find adjacent vertices of selected vertex. if adjacent vertex is infinite return 0. Loop for length of adjust vertices of selected vertex. Repeat the same for all vertices in the DAG. Insert all vertices to result array.
4
2.2 Pseudocode: Insert all vertices of Graph into vertex array.
For length of vertex array. (LOOP1) Find adjacent vertices of each vertex. For length of adjacent vertices of each vertex. (LOOP2) Find shortest path of adjacent vertices. Topological sort of shortest path.
5
2.3 Execution: First two Graphs G1 and G2 are cyclic graphs this algorithm doesn’t work out. The third Graph G3 steps of execution: Step1: find all vertices of Graph Step2: find all adjacent vertices of first vertex Step3: find shortest adjacent vertex and delete other adjacent vertex, find all vertices of this. Step4: find all vertices of selected vertex and find shortest vertex Step5: Select other vertex find adjacent vertex, if all vertices have been visited, end it.
6
Result
7
2.4 The run-time of our algorithm is O(V+E).
8
Thank YOU
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.