AllPairsShortestPath
AllPairsShortestPath[g]
gives a matrix, where the entry is the length of a shortest path in g between vertices
and
.
AllPairsShortestPath[g,Parent]
returns a three-dimensional matrix with dimensions 2*V[g]*V[g], in which the entry is the length of a shortest path from
to
and the
entry is the predecessor of
in a shortest path from
to
.
Details and Options
- AllPairsShortestPath functionality is now available in the built-in Wolfram Language function GraphDistanceMatrix.
- To use AllPairsShortestPath, you first need to load the Combinatorica Package using Needs["Combinatorica`"].
Examples
Basic Examples (2)Summary of the most common use cases

https://wolfram.com/xid/0di8w95y9cfo9b9ickm-rmcvi

https://wolfram.com/xid/0di8w95y9cfo9b9ickm-euxtzb

https://wolfram.com/xid/0di8w95y9cfo9b9ickm-jomgqx


https://wolfram.com/xid/0di8w95y9cfo9b9ickm-c7xwog

AllPairsShortestPath has been superseded by GraphDistanceMatrix:

https://wolfram.com/xid/0di8w95y9cfo9b9ickm-ec1xd2


https://wolfram.com/xid/0di8w95y9cfo9b9ickm-q4ahb

Wolfram Research (2012), AllPairsShortestPath, Wolfram Language function, https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html.
Text
Wolfram Research (2012), AllPairsShortestPath, Wolfram Language function, https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html.
Wolfram Research (2012), AllPairsShortestPath, Wolfram Language function, https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html.
CMS
Wolfram Language. 2012. "AllPairsShortestPath." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html.
Wolfram Language. 2012. "AllPairsShortestPath." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html.
APA
Wolfram Language. (2012). AllPairsShortestPath. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html
Wolfram Language. (2012). AllPairsShortestPath. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html
BibTeX
@misc{reference.wolfram_2025_allpairsshortestpath, author="Wolfram Research", title="{AllPairsShortestPath}", year="2012", howpublished="\url{https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html}", note=[Accessed: 12-July-2025
]}
BibLaTeX
@online{reference.wolfram_2025_allpairsshortestpath, organization={Wolfram Research}, title={AllPairsShortestPath}, year={2012}, url={https://reference.wolfram.com/language/Combinatorica/ref/AllPairsShortestPath.html}, note=[Accessed: 12-July-2025
]}