Let be a weighted directed acyclic graph with edges and vertices. Given and a source vertex in , which one of the following options gives the worst case time complexity of the fastest algorithm to find the lengths of shortest paths from to all vertices that are reachable from in
View worked solution
Answer: A
The single-source shortest path (SSSP) problem on a weighted Directed Acyclic Graph (DAG) can be solved efficiently using topological sorting in time.
The algorithm proceeds as follows:
- Topological Sort: Find a topological ordering of the vertices of . This takes time using Depth-First Search (DFS) or Kahn's algorithm.
- Initialization: Set the distance to the source vertex as , and for all other vertices , set . This takes time.
- Relaxation: Process each vertex in the topological order. For each outgoing edge with weight , update the distance:Since each vertex and edge is processed exactly once, this step takes time.
Therefore, the total worst-case time complexity of the fastest algorithm is .
Correct Option: A
Free practice · Your answers on this page are not saved.
