How would I find the min distance between two vertices in a graph.
What function should I use?
For example, in the above, $d(2,4)=2$ and $d(2,3)=1$
How would I find the min distance between two vertices in a graph.
What function should I use?
For example, in the above, $d(2,4)=2$ and $d(2,3)=1$
You can use GraphDistance
to do that:
g = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1, 1 <-> 4}];
GraphDistance[g, 2, 3]
GraphDistance[g, 2, 4]
(* 1 *)
(* 2 *)