BUILT-IN MATHEMATICA SYMBOL

# FindShortestPath

FindShortestPath[g, s, t]
finds the shortest path from source vertex s to target vertex t in the graph g.

FindShortestPath[g, s, All]
generates a ShortestPathFunction[...] that can be applied repeatedly to different t.

FindShortestPath[g, All, t]
generates a ShortestPathFunction[...] that can be applied repeatedly to different s.

generates a ShortestPathFunction[...] that can be applied to different s and t.

## Details and OptionsDetails and Options

• FindShortestPath[g, s, t] gives a path from s to t.
• FindShortestPath[g, s] is equivalent to FindShortestPath[g, s, All].
• is equivalent to .
• For an unweighted graph, edge length is assumed to be 1.
• For a weighted graph, edge length is taken to be the weight.
• A Method option can also be given. Possible Method settings include:
•  "BellmanFord" supports positive and negative weights "Dijkstra" supports positive weights

## ExamplesExamplesopen allclose all

### Basic Examples (1)Basic Examples (1)

Find a shortest path between two individual vertices in a graph:

 Out[1]=
 Out[2]=

Highlight the path:

 Out[3]=