WOLFRAM

Subgraph[g,{v1,v2,}]

gives the subgraph of the graph g generated by the vertices vi.

Subgraph[g,{e1,e2,}]

gives the subgraph generated by the edges ej.

Subgraph[g,patt]

gives the subgraph generated by the vertices and edges that match the pattern patt.

Subgraph[{vw,},]

uses rules vw to specify the graph g.

Details and Options

  • The subgraph generated by the vertices v1,v2, includes the vertices vi and all edges connecting them in the original graph g.
  • The subgraph generated by the edges e1,e2, includes the edges ej and all edges connecting vertices vi of ej in the original graph g.
  • Subgraph works with undirected graphs, directed graphs, multigraphs, and mixed graphs.

Examples

open allclose all

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

Give a subgraph of a complete graph:

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

Highlight the subgraph within the main graph:

Out[3]=3

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

Subgraph works with undirected graphs:

Out[1]=1

Directed graphs:

Out[1]=1

Multigraph:

Out[1]=1

Mixed graph:

Out[1]=1

Use rules to specify the graph:

Out[1]=1

Use patterns to select subgraphs:

Out[1]=1

Find the subgraph with edges that are incident to 3:

Out[2]=2

Find the subgraph with vertices less than 6:

Out[3]=3

Subgraph works with large graphs:

Out[2]=2

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

Select random subgraphs of size 5:

Out[3]=3

Find all the subgraphs of the graph g that are isomorphic to the graph h:

Out[1]=1

Enumerate all subsets of vertices that have the same number of vertices as h:

Select the subgraphs that are isomorphic to h:

Highlight them:

Out[4]=4

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

The vertices of subgraphs are subsets of the original vertices:

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

The edges of subgraphs are subsets of the original edges:

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

The subgraph of a complete graph is a complete graph:

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

Neat Examples  (1)Surprising or curious use cases

Subtract random neighborhoods from a grid:

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

Text

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

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

CMS

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

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

APA

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

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

BibTeX

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

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

BibLaTeX

@online{reference.wolfram_2025_subgraph, organization={Wolfram Research}, title={Subgraph}, year={2015}, url={https://reference.wolfram.com/language/ref/Subgraph.html}, note=[Accessed: 24-May-2025 ]}

@online{reference.wolfram_2025_subgraph, organization={Wolfram Research}, title={Subgraph}, year={2015}, url={https://reference.wolfram.com/language/ref/Subgraph.html}, note=[Accessed: 24-May-2025 ]}