FindPath

FindPath[g,s,t]
finds a path between vertex s and vertex t in the graph g.

FindPath[g,s,t,k]
finds a path of length at most k between vertex s and vertex t in the graph g.

FindPath[g,s,t,{k}]
finds a path of length exactly k.

FindPath[g,s,t,{kmin,kmax}]
finds a path of length between and .

FindPath[g,s,t,kspec,n]
finds at most n paths.

DetailsDetails

  • FindPath returns a list of paths from s to t. Each path is given as a list of vertices.
  • FindPath[g,s,t,kspec,All] finds all the paths.
  • For weighted graphs, FindPath[g,s,t,k] gives all paths with total weights less than k.
  • FindPath works with undirected graphs, directed graphs, weighted graphs, multigraphs, and mixed graphs.

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

Find a path between two individual vertices in a graph:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=

Highlight the path:

In[3]:=
Click for copyable input
Out[3]=

Find all paths between two individual vertices in a graph:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
Introduced in 2014
(10.0)