PRODUCTS
Products Overview
Mathematica
Mathematica for Students
Mathematica Home Edition
Wolfram
CDF Player
(free download)
Computable Document Format (CDF)
web
Mathematica
grid
Mathematica
Wolfram
Workbench
Wolfram
SystemModeler
Wolfram
Finance Platform
Mathematica
Add-Ons
Wolfram|Alpha Products
SOLUTIONS
Solutions Overview
Engineering
Aerospace Engineering & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Materials Science
Mechanical Engineering
Operations Research
Optics
Petroleum Engineering
Biotechnology & Medicine
Bioinformatics
Medical Imaging
Finance, Statistics & Business Analysis
Actuarial Sciences
Data Analysis & Mining
Econometrics
Economics
Financial Engineering & Mathematics
Financial Risk Management
Statistics
Software Engineering & Content Delivery
Authoring & Publishing
Interface Development
Software Engineering
Web Development
Science
Astronomy
Biological Sciences
Chemistry
Environmental Sciences
Geosciences
Social & Behavioral Sciences
Design, Arts & Entertainment
Game Design, Special Effects & Generative Art
Education
STEM Education Initiative
Higher Education
Community & Technical College Education
Primary & Secondary Education
Students
Technology
Computable Document Format (CDF)
High-Performance & Parallel Computing (HPC)
See Also: Technology Guide
PURCHASE
Online Store
Other Ways to Buy
Volume & Site Licensing
Contact Sales
Software
Service
Upgrades
Training
Books
Merchandise
SUPPORT
Support Overview
Knowledge Base
Learning Center
Community & Forums
Training
Does My Site Have a License?
Wolfram User Portal
COMPANY
About Wolfram Research
News & Events
Wolfram Blog
Partnerships
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
All Sites
Wolfram|Alpha
Demonstrations Project
MathWorld
Integrator
Wolfram Functions Site
Mathematica Journal
Wolfram Media
Wolfram
Tones
Wolfram Science
Stephen Wolfram
DOCUMENTATION CENTER SEARCH
New to
Mathematica
?
Find your learning path
»
Mathematica
>
Mathematics and Algorithms
>
Graphs & Networks
>
Graph Measures & Metrics
>
GraphDistance
>
Mathematica
>
Visualization and Graphics
>
Graphs & Networks
>
Graph Measures & Metrics
>
GraphDistance
>
BUILT-IN MATHEMATICA SYMBOL
GraphDistanceMatrix
BreadthFirstScan
DepthFirstScan
See Also »
|
Graph Measures & Metrics
Paths and Cycles
Graphs & Networks
Summary of New Features in Mathematica 8
New in 8.0: Alphabetical Listing
New in 8.0: Mathematics & Algorithms
More About »
GraphDistance
GraphDistance
gives the distance from source vertex
s
to target vertex
t
in the graph
g
.
GraphDistance
gives the distance from
s
to all vertices of the graph
g
.
MORE INFORMATION
GraphDistance
will give the length of the shortest path between
s
and
t
.
The distance is
Infinity
when there is no path between
s
and
t
.
For a weighted graph, the distance is the minimum of the sum of weights along any path between
s
and
t
.
EXAMPLES
CLOSE ALL
Basic Examples
(1)
Give the distance for a grid graph:
Give the distance for a grid graph:
In[1]:=
Out[1]=
In[2]:=
Out[2]=
Scope
(4)
GraphDistance
works with undirected graphs:
Directed graphs:
Weighted graphs:
The distance between two vertices is the smallest total edge weight along any path:
Works with large graphs:
Options
(3)
The method is automatically chosen depending on input:
method will use the weight 1 for every edge:
can be used for graphs with positive edge weights only:
Applications
(5)
Find the distance between opposite corners of a
GridGraph
of size
:
Find the distance between opposite corners in a
-dimensional
GridGraph
of size
:
Visualize distance from a vertex in a tree:
Obtain the maximum distance from the vertex to any other vertex:
Set color proportionally to distance:
The expected distance between two vertices for Bernoulli graphs with probability
is
:
Illustrate the
DamerauLevenshteinDistance
for short words over a small alphabet:
Find the Damerau-Levenshtein distance between two words:
Check the result:
Properties & Relations
(3)
The distance between two vertices can be found using
FindShortestPath
:
Distance matrix:
In a connected graph, the
VertexEccentricity
can be computed using
GraphDistance
:
The distance between two vertices belonging to different connected components is
Infinity
:
SEE ALSO
GraphDistanceMatrix
BreadthFirstScan
DepthFirstScan
MORE ABOUT
Graph Measures & Metrics
Paths and Cycles
Graphs & Networks
Summary of New Features in
Mathematica
8
New in 8.0: Alphabetical Listing
New in 8.0: Mathematics & Algorithms
New in 8