Macaulay2 » Documentation
Packages » Graphs :: distance
next | previous | forward | backward | up | index | toc

# distance -- Computes the distance between two vertexSet in a graph

- Usage:
    `d = distance(G,v,u)`
- Inputs:
  - G, a graph,
  - v, a thing,
  - u, a thing,
- Outputs:
  - d, an integer, The distance between vertexSet v and u

## Description

The distance between two vertexSet is calculated as the number of edges in the shortest path between the two vertexSet. If the two vertexSet are not connected, the distance between them is infinity by convention.

    i1 : G = graph({{1,2},{2,3},{3,4}},EntryMode=>"edges");

    i2 : d = distance (G,1,4)

    o2 = 3

    i3 : G = graph({1,2,3,4},{{2,3},{3,4}});

    i4 : d = distance(G, 1, 4)

    o4 = infinity

    o4 : InfiniteNumber

## See also

- diameter(Graph) -- Computes the diameter of a graph
- distanceMatrix -- Computes the distance matrix of a digraph

## Ways to use distance:

- `distance(Digraph,Thing,Thing)`
- distance(Digraph,Thing) (missing documentation)

## For the programmer

The object distance is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Graphs.m2:3514:0.