({{, (RefLink[GraphDifference, paclet:ref/GraphDifference])[(Subscript[g, 1]),(Subscript[g, 2])] 
gives the graph difference of the graphs (Subscript[g, 1]) and (Subscript[g, 2]).}, {, (RefLink[GraphDifference, paclet:ref/GraphDifference])[{v->w,…},…]
uses rules v->w to specify the graph g.}})

OpenersNotesSection(Spacer1)Details and Options

The graph difference (RefLink[Graph, paclet:ref/Graph])[(Subscript[v, 1]),(Subscript[e, 1])]∖(RefLink[Graph, paclet:ref/Graph])[(Subscript[v, 2]),(Subscript[e, 2])] is given by (RefLink[Graph, paclet:ref/Graph])[(Subscript[v, 1])⋃(Subscript[v, 2]),(Subscript[e, 1])∖ (Subscript[e, 2])].

(RefLink[GraphDifference, paclet:ref/GraphDifference]) works with undirected graphs, directed graphs, multigraphs, and mixed graphs.

OpenersPrimaryExamplesSection(Spacer1)Examples  (12)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Obtain the graph difference of two graphs:

g=;h=;

x=GraphDifference[g,h]

Highlight the graph difference:

HighlightGraph[g,%,GraphHighlightStyle->"Thick"]

OpenersExampleSection1(Spacer1)Scope  (5)

(RefLink[GraphDifference, paclet:ref/GraphDifference]) works with undirected graphs:

GraphDifference[,]

Directed graphs:

GraphDifference[,]

Multigraphs:

GraphDifference[,]

Mixed graphs:

GraphDifference[,]

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}]

OpenersExampleSection3(Spacer1)Properties & Relations  (6)

The vertices of the graph difference are the union of the vertices of the graphs:

g1=;g2=;

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=;g2=;

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[,]

EmptyGraphQ[%]

The graph difference of any graph and its (RefLink[CompleteGraph, paclet:ref/CompleteGraph]) is isomorphic to the complement of the graph:

g=;

IsomorphicGraphQ[GraphDifference[CompleteGraph[6],g], GraphComplement[g]]

The (RefLink[GraphDifference, paclet:ref/GraphDifference]) of two graphs has the same vertices as (RefLink[GraphUnion, paclet:ref/GraphUnion]):

VertexList[GraphDifference[,]]==VertexList[GraphUnion[,]]

The (RefLink[GraphDifference, paclet:ref/GraphDifference]) of two graphs has the same vertices as (RefLink[GraphIntersection, paclet:ref/GraphIntersection]):

VertexList[GraphDifference[,]]==VertexList[GraphIntersection[,]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[GraphComplement, paclet:ref/GraphComplement])  ▪  (RefLink[GraphUnion, paclet:ref/GraphUnion])  ▪  (RefLink[GraphIntersection, paclet:ref/GraphIntersection])  ▪  (RefLink[GraphDisjointUnion, paclet:ref/GraphDisjointUnion])  ▪  (RefLink[BooleanGraph, paclet:ref/BooleanGraph])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Operations and Modifications, paclet:guide/GraphModifications])}})}})