We deliver solutions for the AI eraâcombining symbolic computation, data-driven insights and deep technical expertise
GraphPath[g,start,end]
finds a shortest path between vertices start and end in graph g.
Examplesopen all close all Basic Examples (2)This defines a small directed graph:
This finds the shortest path from vertex 1 to vertex 3:
This finds the shortest path from vertex 1 to vertex 3, ignoring the edge weights:
GraphPath has been superseded by FindShortestPath:
Options (1) Method (1)Because of the negative edge weight, the Dijkstra algorithm cannot be applied:
The Bellman–Ford algorithm works:
This defines a small graph with a negative cycle:
The Dijkstra algorithm does not work for negative edge weights:
The Bellman–Ford algorithm detects a negative weight cycle:
The default algorithm for graphs with negative edge weights is Bellman–Ford:
Properties & Relations (1)This defines a small directed graph:
This finds the shortest path from vertex 1 to 3:
This finds the distance of this path, taking into account the edge weights:
This finds the distance of this path, ignoring the edge weights:
Possible Issues (1)This defines a small directed graph:
If there are negative edge weights, the "Dijkstra" method cannot be used:
This finds the shortest path from vertex 1 to vertex 3 using the "BellmanFord" method:
Interactive Examples (1)This shows how to travel from vertex 1 to 7 through the shortest path:
Wolfram Research (2007), GraphPath, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html. TextWolfram Research (2007), GraphPath, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html.
CMSWolfram Language. 2007. "GraphPath." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html.
APAWolfram Language. (2007). GraphPath. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html
BibTeX@misc{reference.wolfram_2025_graphpath, author="Wolfram Research", title="{GraphPath}", year="2007", howpublished="\url{https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html}", note=[Accessed: 17-August-2025]}
BibLaTeX@online{reference.wolfram_2025_graphpath, organization={Wolfram Research}, title={GraphPath}, year={2007}, url={https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html}, note=[Accessed: 17-August-2025]}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4