GraphDifference[g1,g2]
gives the graph difference of the graphs g1 and g2.
GraphDifference[{vw,…},…]
uses rules vw to specify the graph g.
GraphDifference
GraphDifference[g1,g2]
gives the graph difference of the graphs g1 and g2.
GraphDifference[{vw,…},…]
uses rules vw to specify the graph g.
Details and Options
- The graph difference Graph[v1,e1]∖Graph[v2,e2] is given by Graph[v1⋃v2,e1∖ e2].
- GraphDifference works with undirected graphs, directed graphs, multigraphs, and mixed graphs.
Examples
open all close allBasic Examples (1)
Scope (5)
GraphDifference works with undirected graphs:
GraphDifference[[image], [image]]GraphDifference[[image], [image]]GraphDifference[[image], [image]]GraphDifference[[image], [image]]Use rules to specify the graph:
GraphDifference[{1 -> 2, 2 -> 3, 3 -> 1, 4 -> 3, 2 -> 4}, {1 -> 2, 3 -> 2, 4 -> 3, 4 -> 1}]Properties & Relations (6)
The vertices of the graph difference are the union of the vertices of the graphs:
g1 = [image];g2 = [image];VertexList[GraphDifference[g1, g2]] == Union[VertexList[g1], VertexList[g2]]The edges of the graph difference are the complement of the edges of the graphs:
g1 = [image];g2 = [image];edgeSameQ[e1_, e2_] := SameQ[e1, e2] || SameQ[e1, Reverse[e2]]EdgeList[GraphDifference[g1, g2]] == Complement[EdgeList[g1], EdgeList[g2], SameTest -> edgeSameQ]The graph difference of any graph and itself is an empty graph:
GraphDifference[[image], [image]]EmptyGraphQ[%]The graph difference of any graph and its CompleteGraph is isomorphic to the complement of the graph:
g = [image];IsomorphicGraphQ[GraphDifference[CompleteGraph[6], g], GraphComplement[g]]The GraphDifference of two graphs has the same vertices as GraphUnion:
VertexList[GraphDifference[[image], [image]]] == VertexList[GraphUnion[[image], [image]]]The GraphDifference of two graphs has the same vertices as GraphIntersection:
VertexList[GraphDifference[[image], [image]]] == VertexList[GraphIntersection[[image], [image]]]Related Guides
Text
Wolfram Research (2010), GraphDifference, Wolfram Language function, https://reference.wolfram.com/language/ref/GraphDifference.html (updated 2015).
CMS
Wolfram Language. 2010. "GraphDifference." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/GraphDifference.html.
APA
Wolfram Language. (2010). GraphDifference. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GraphDifference.html
BibTeX
@misc{reference.wolfram_2026_graphdifference, author="Wolfram Research", title="{GraphDifference}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/GraphDifference.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_graphdifference, organization={Wolfram Research}, title={GraphDifference}, year={2015}, url={https://reference.wolfram.com/language/ref/GraphDifference.html}, note=[Accessed: 13-June-2026]}