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 kmin and kmax.
FindPath[g,s,t,kspec,n]
finds at most n paths.
FindPath[{vw,…},…]
uses rules vw to specify the graph g.
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 kmin and kmax.
FindPath[g,s,t,kspec,n]
finds at most n paths.
FindPath[{vw,…},…]
uses rules vw to specify the graph g.
Details
- 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 at most k.
- FindPath works with undirected graphs, directed graphs, weighted graphs, multigraphs, and mixed graphs.
Examples
open all close allBasic Examples (2)
Find a path between two individual vertices in a graph:
g = [image];FindPath[g, 3, 2]HighlightGraph[g, PathGraph[First[%]]]Find all paths between two individual vertices in a graph:
g = ExampleData[{"NetworkGraph", "Friendship"}];FindPath[g, "Anna", "Larry", Infinity, All]Scope (12)
Specification (7)
FindPath works with undirected graphs:
FindPath[[image], 2, 7]FindPath[[image], 2, 12]FindPath[[image], 2, 7]FindPath[[image], 2, 7]FindPath[[image], 2, 4]Use rules to specify the graph:
FindPath[{1 -> 2, 1 -> 4, 2 -> 3, 2 -> 5, 3 -> 6, 4 -> 5, 4 -> 7, 5 -> 6, 5 -> 8, 6 -> 9, 7 -> 8, 7 -> 10, 8 -> 9, 8 -> 11, 9 -> 12, 10 -> 11, 11 -> 12}, 2, 12]FindPath works with large graphs:
g = GridGraph[{10, 10, 10, 10}];FindPath[g, 1, 10000]//Short//TimingEnumeration (5)
FindPath[[image], 1, 12, {7}]FindPath[[image], 1, 12, 6]A path of length between 5 and 7:
FindPath[[image], 1, 12, {5, 7}]Find all paths between two individual vertices:
FindPath[[image], 1, 12, Infinity, All]//ShortFindPath gives an empty list if there is no path:
FindPath[[image], 1, 12]Applications (2)
Find paths of length at most 5 along the seams of a soccer ball:
g = PolyhedronData["SoccerBall", "Skeleton"];path = FindPath[g, 19, 30, 6, All]coords = PolyhedronData["SoccerBall", "Vertices"];Graphics3D[Join[{Glow[Gray], PolyhedronData["SoccerBall", "GraphicsComplex"], Red}, Sphere[#, 0.3]& /@ coords[[{19, 30}]], {Red, Tube[coords[[#]], 0.2]}]]& /@ pathPlan a trip in the London Underground:
g = \!\(\*GraphicsBox[«4»]\);Find a trip from Arsenal to Alperton with at most 16 stops:
FindPath[g, "Arsenal", "Alperton", 17, All]Properties & Relations (2)
s = 1;
t = 12;
g = GridGraph[{3, 4}, VertexSize -> {s -> Medium, t -> Medium}]FindPath[g, s, t, {GraphDistance[g, s, t]}, All]HighlightGraph[g, PathGraph[#]]& /@ %FindPath only returns simple paths:
FindPath[[image], 1, 3, Infinity, All]Related Guides
Text
Wolfram Research (2014), FindPath, Wolfram Language function, https://reference.wolfram.com/language/ref/FindPath.html (updated 2015).
CMS
Wolfram Language. 2014. "FindPath." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/FindPath.html.
APA
Wolfram Language. (2014). FindPath. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FindPath.html
BibTeX
@misc{reference.wolfram_2026_findpath, author="Wolfram Research", title="{FindPath}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/FindPath.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_findpath, organization={Wolfram Research}, title={FindPath}, year={2015}, url={https://reference.wolfram.com/language/ref/FindPath.html}, note=[Accessed: 13-June-2026]}