Replacement for GraphJoin

GraphComputation`GraphJoin

GraphComputation`GraphJoin[PathGraph[{a, b}], PathGraph[{c, d, e}], 
 VertexLabels -> "Name", ImagePadding -> 10, 
 GraphLayout -> "MultipartiteEmbedding"]

enter image description here

This undocumented function works in both version 9.0 and version 11.3.


The function you reference still works fine, but it is part of the Combinatorica package. You need to load the package first, and work with Combinatorica's own graph datatype. Combinatorica precedes Mathematica's built-in graph datatype by many years, and is not interoperable with it.

That said, it is relatively easy to implement an equivalent function for built-in Graph objects as well:

graphJoin1[g1_?GraphQ, g2_?GraphQ, opt : OptionsPattern[]] :=
  GraphUnion[
    GraphDisjointUnion[g1, g2], 
    CompleteGraph[{VertexCount[g1], VertexCount[g2]}], 
    opt
  ]

graphJoin1[PathGraph[{a, b}], PathGraph[{c, d, e}],
 VertexLabels -> "Name", GraphLayout -> "MultipartiteEmbedding"]

enter image description here

If you want to preserve vertex names (when the original vertex sets are disjoint), you can write a slightly more complicated function:

graphJoin2[g1_?GraphQ, g2_?GraphQ, opt : OptionsPattern[]] := 
 With[{g = graphJoin1[g1, g2, opt], vl1 = VertexList[g1], vl2 = VertexList[g2]},
   If[DisjointQ[vl1, vl2],
     VertexReplace[g, Thread[VertexList[g] -> Join[vl1, vl2]]],
     g
   ]
 ]

This solution uses only supported and documented functionality.


The original version of this answer used the implementation

graphJoin[g1_?UndirectedGraphQ, g2_?UndirectedGraphQ, opt : OptionsPattern[Graph]] :=
 Graph[
   Join[
     EdgeList@IndexGraph[g1],
     EdgeList@IndexGraph[g2, VertexCount[g1] + 1],
     EdgeList@CompleteGraph[{VertexCount[g1], VertexCount[g2]}]
   ],
   opt
 ]