Dijkstra Algorithm

Shortest Path

Shortest Path Definition

: Among paths between two vertices in a graph with weighted edges, the path with minimum sum of edge weights

Shortest Path from One Starting Vertex to End Vertex (one to all)

  • Dijkstra Algorithm

    • Does not allow negative weights

  • Bellman-Ford Algorithm

    • Allows negative weights

Shortest Paths for All Vertices

  • Floyd-Warshall Algorithm

Dijkstra Algorithm

Method of finding shortest paths by selecting vertices with minimum distance from the starting vertex

  • Vertex x exists in the shortest path from starting vertex (s) to end vertex (t)

  • At this time, the shortest path consists of the shortest path from s to x and the shortest path from x to t

  • Algorithm using greedy technique, similar to Prim Algorithm of MST

  • Given an adjacency matrix graph and starting vertex, Dijkstra algorithm can find the shortest distance from the starting vertex to all vertices

Time Complexity

: O(logN)

Implementation

Dijkstra + adjacency list

Last updated