Europ. J. Combinatorics (1987) 8, 209-212
Factoring a Graph in Polynomial Time
PETER WINKLER
We present a polynomial-time algorithm for deciding whether a given connected graph is a
non-trivial Cartesian product. The method entails first representing the graph as an isometric
subgraph of a Cartesian product of graphs, then finding a suitable partition of the factors.
The Cartesian product G x H of graphs G and H has as vertices the pairs (g, h) with g
a vertex of G and h a vertex of H; (gl, hI) is connected by an edge to (g2' h
2
) in G x H just
when {gl' g2} is an edge of G and hI = h2' or when g, = g2 and {h" h
2
} is an edge of H.
The Cartesian product admits unique factorization (Sabidussi [4]) but until recently no
efficient algorithm was known for producing such a factorization.
If unconnected graphs are permitted then the factorization problem is at least as difficult
as 'graph isomorphism'; for, one could determine whether two connected graphs G and H
are isomorphic by deciding whether a graph with two vertices and no edge is a factor of the
disjoint union of G and H. The question of whether there is a polynomial algorithm for
deciding if a connected graph is a non-trivial Cartesian product--equivalently, for finding
its unique factorization-was posed by Welsh [5], Imrich [3], and probably Sabidussi as
well. Recently, this question was settled in the affirmative (independently of this author) by
Feigenbaum, Hershberger and Schaffer [1] using towers of equivalence relations. Our
methods are completely different, making use of results in [2] in which graphs are regarded
as metric spaces.
THEOREM. There is a polynomial algorithm for deciding whether a given connected graph
G is a non-trivial Cartesian product, and for finding the prime factorization of G.
PROOF. If u and v are two vertices of G, let d(u, v) be the number of edges in a
shortest path between them. Define the relation 13 between edges of the graph as follows:
if e = (x, y) and f = (u, v) then ef3f iff d(x, u) + d(y, v) # d(x, v) + d(y, u). Let
E be the edge· of G and E" ... , Ek the equivalence classes of the transitive closure
of 13. The factor graph G
i
, 1 i k, is formed from G by contracting every edge not
in Ei to a poivt; concatenating the natural projections J;: G --+ G
i
yields a map f from
G to the Carte!>ian product of the GiS. This product may itself be exponential in size,
but we do not need to list its vertices; in fact even the structure of the GiS is irrelevant until
later.
The first lemma lists some useful facts about this 'canonical representation' f: G '-+ TIG
i
;
all follow immediately from Theorems 1-3 in [2].
LEMMA 1. The mapfis isometric, i.e. d(u, v) = dG,(J;(u),J;(v)) for any pair u, v of
vertices in G; further, each G
i
has at least two vertices and the projections J;: G --+ G
i
are
surjective. The number offactors k is called the dimension ofG andfis the unique embedding
of G with the above properties and at least k factors; the dimension of each G
i
is 1.
If G is the Cartesian product of graphs H, and H2 then there is a partition of the index
set S = {1,2, ... , k} into sets S, and S2, and canonical representations h/ H
j
--+ TIiESjGi for
209
0195-6698/87/020209+04 $02.00/0 © 1987 Academic Press Inc. (London) Limited
CORE Metadata, citation and similar papers at core.ac.uk
Provided by Elsevier - Publisher Connector