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

# neighbors -- returns the neighbors of a vertex in a graph

- Usage:
    `N = neighbors(G,v)`
- Inputs:
  - G, a graph,
  - v, a thing,
- Outputs:
  - N, a set, the neighbors of vertex v in graph G

## Description

The neighbors of a vertex v are all the vertexSet of G adjacent to v. That is, if u is a neighbor to v, {v,u} is an edge of G.

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

    i2 : neighbors(G,3)

    o2 = set {4, 2}

    o2 : Set

## See also

- nonneighbors -- returns the non-neighbors of a vertex in a graph

## Ways to use neighbors:

- `neighbors(Graph,Thing)`

## For the programmer

The object neighbors is a method function.

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