0% found this document useful (0 votes)
2 views4 pages

Shortest Path

The document outlines a Dijkstra algorithm for finding the shortest path from a source vertex to all other vertices in a graph. It includes pseudo-code for the algorithm and mentions the use of a priority queue for efficient distance updates. The time complexity of Dijkstra's algorithm is O((V + E) log V), where V is the number of vertices and E is the number of edges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Shortest Path

The document outlines a Dijkstra algorithm for finding the shortest path from a source vertex to all other vertices in a graph. It includes pseudo-code for the algorithm and mentions the use of a priority queue for efficient distance updates. The time complexity of Dijkstra's algorithm is O((V + E) log V), where V is the number of vertices and E is the number of edges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

You need to write an algorithm to find shortest path from A to all other vertices

●​ Write pseudo code for the given problem, you can use Dijkstra, Floyd Warshall or
Topological sort for this
●​ Analyze the time complexity of algorithm and document that
●​ Write code in any programming language and share the results

Pseudo-code
Algorithm Dijkstra(Graph, source):

Initialize distance[source] = 0 and all other distances to ∞


Create a priority queue (min-heap) and push (0, source)
While priority queue is not empty:
Extract node u with the smallest distance
For each neighbor v of u:
Compute new distance: newDist = distance[u] + weight(u, v)
If newDist < distance[v]:
Update distance[v] = newDist
Push (newDist, v) into priority queue
Return the distance array

Time Complexity Analysis

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy