0
$\begingroup$

How would I find the min distance between two vertices in a graph.

What function should I use?

enter image description here

For example, in the above, $d(2,4)=2$ and $d(2,3)=1$

$\endgroup$
1
  • $\begingroup$ By "min distance", do you mean the length of the minimum path between to specified vertices? $\endgroup$
    – m_goldberg
    Commented May 1, 2016 at 3:17

1 Answer 1

4
$\begingroup$

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 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.