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$
  • $\begingroup$ By "min distance", do you mean the length of the minimum path between to specified vertices? $\endgroup$ – m_goldberg May 1 '16 at 3:17
3
$\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, privacy policy and cookie policy

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