# Dijkstra Algorithm

Dijkstra algorithm finds the shortest path from a certain vertex on a directed graph without negative weights.

## Steps

- We have S as start vertex
- Create a priority queue PQ, and add S to PQ
- Set the distance to S be 0, and to others be ∞
- Take every closest vertex from PQ:
- Skip this vertex if it is visited
- Set this vertex to be visited
- For every edge connected to this vertex, update the distance and the path to the edge's target if the distance can be shorter

- After PQ being empty, we get the shortest paths from S to every vertex on the graph

## Image Demo

## Links

Wikipedia page of Dijkstra's algorithm

UW-Madison CS 400 Reading of Graphs