In graph theory, the shortest path problem finds a path between two vertices such that the weight of its edges is minimised. A few definitions:

  • The problem operates on a weighted, directed graph .
  • A weight function maps edges to weights, .
  • The weight of path is the sum of the weights of each constituent edge from vertices .

The shortest path is given by the smallest weight, i.e., the shortest-path weight from to is defined as:

What possible applications does this have?

Some shortest path algorithms include:

Variations

SSSP — single source to all vertices SDSP — single destination from all vertices reverse of SSSP single pair shortest path — from vertex to all pair — self explanatory we can use SSSP to solve all variants

bellman ford for each edge dijkstra’s for each vertex, store in matrix lookup matrix, s(u, v) + s(v, u) take smallest dijkstra but we modify the relax function s -p u v; either bottleneck is in p or in new edge (u, v)

relax(u, v, w)
	if (v.d < min(u.d, w(u, v)))
		v.d = min(u.d, w(u, v))
		v.pi = u

we initialise source with , initialise everything else with 0