WOLFRAM

gives the graph neighborhood of a vertex v in the graph g.

NeighborhoodGraph[g,{a1,a2,}]

gives the graph neighborhood of the ai that can be vertices, edges, or subgraphs of g.

gives the graph neighborhood of the vertices and edges that match the pattern patt.

gives the neighborhood up to distance d.

NeighborhoodGraph[{vw,},]

uses rules vw to specify the graph g.

Details and Options

  • The neighborhood graph for a vertex v is given by vertices adjacent to v and the edges connecting them.
  • The neighborhood graph for an edge e is the neighborhood graph for the vertices of e.
  • The neighborhood graph for a subgraph h is the neighborhood graph for the vertices in h.
  • The neighborhood graph at distance d is the neighborhood graph for the vertices of the neighborhood graph at distance d-1.
  • The default value for d is 1.
  • NeighborhoodGraph works with undirected graphs, directed graphs, multigraphs, and mixed graphs.

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Give the neighborhood from vertex 1 in a graph:

Out[1]=1
Out[2]=2

From a set of vertices:

Out[3]=3

Give the neighborhood up to distance k from the vertices:

Out[1]=1
Out[2]=2

Scope  (8)Survey of the scope of standard use cases

NeighborhoodGraph works with undirected graphs:

Out[1]=1
Out[2]=2

Directed graphs:

Out[2]=2

Multigraphs:

Out[2]=2

Mixed graphs:

Out[2]=2

NeighborhoodGraph works with vertices:

Out[1]=1
Out[2]=2

Edges:

Out[3]=3

Use rules to specify the graph:

Out[2]=2

Use patterns to specify a set of vertices:

Out[1]=1
Out[2]=2

NeighborhoodGraph works with large graphs:

Out[2]=2

Applications  (2)Sample problems that can be solved with this function

Highlight the neighborhood from the vertices in CompleteGraph:

Out[2]=2

CycleGraph:

Out[4]=4

StarGraph:

Out[6]=6

GridGraph:

Out[8]=8

CompleteKaryTree:

Out[10]=10

PathGraph:

Out[12]=12

RandomGraph:

Out[14]=14

Manipulate the neighborhood of vertices:

Out[1]=1

Properties & Relations  (2)Properties of the function, and connections to other functions

Use Subgraph to find the neighborhood graph of a set of vertices:

Out[1]=1

Highlight the subgraph:

Out[4]=4

This is equivalent to:

Out[5]=5

The neighborhood of a vertex in a complete graph is the graph itself:

Out[1]=1
Out[2]=2

Neat Examples  (2)Surprising or curious use cases

Pick out random neighborhoods from a grid:

Out[2]=2

Subtract random neighborhoods from a grid:

Out[2]=2
Wolfram Research (2010), NeighborhoodGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/NeighborhoodGraph.html (updated 2015).
Wolfram Research (2010), NeighborhoodGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/NeighborhoodGraph.html (updated 2015).

Text

Wolfram Research (2010), NeighborhoodGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/NeighborhoodGraph.html (updated 2015).

Wolfram Research (2010), NeighborhoodGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/NeighborhoodGraph.html (updated 2015).

CMS

Wolfram Language. 2010. "NeighborhoodGraph." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/NeighborhoodGraph.html.

Wolfram Language. 2010. "NeighborhoodGraph." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/NeighborhoodGraph.html.

APA

Wolfram Language. (2010). NeighborhoodGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NeighborhoodGraph.html

Wolfram Language. (2010). NeighborhoodGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NeighborhoodGraph.html

BibTeX

@misc{reference.wolfram_2025_neighborhoodgraph, author="Wolfram Research", title="{NeighborhoodGraph}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/NeighborhoodGraph.html}", note=[Accessed: 25-March-2025 ]}

@misc{reference.wolfram_2025_neighborhoodgraph, author="Wolfram Research", title="{NeighborhoodGraph}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/NeighborhoodGraph.html}", note=[Accessed: 25-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_neighborhoodgraph, organization={Wolfram Research}, title={NeighborhoodGraph}, year={2015}, url={https://reference.wolfram.com/language/ref/NeighborhoodGraph.html}, note=[Accessed: 25-March-2025 ]}

@online{reference.wolfram_2025_neighborhoodgraph, organization={Wolfram Research}, title={NeighborhoodGraph}, year={2015}, url={https://reference.wolfram.com/language/ref/NeighborhoodGraph.html}, note=[Accessed: 25-March-2025 ]}