Theorem. [Hopcroft–Tarjan 1974] There exists an O(n) time algorithm to
determine whether a graph is planar.
Efficient Planarity Testing
JOHN HOPCROFT AND ROBERT
TAR JAN
Cornell University, Ithaca, New York
ABSTRACT. This paper describes an efficient algorithm to determine whether an arbitrary graph G
can be embedded in the plane. The algorithm may be viewed as an iterative version of a method
originally proposed by Auslander and Parter and correctly formulated by Goldstein. The algorithm
uses depth-first search and has
O(V)
time and space bounds, where V is the number of vertices in
G. An ALGOS implementation of the algorithm successfully tested graphs with as many as 900 vertices
in less than 12 seconds.
KEY
WORDS AND PHRASES: algorithm, complexity, depth-first search, embedding, genus, graph,
palm tree, planarity, spanning tree
CR CATEGORIES:
3.24, 5.25, 5.32
1. Introduction
Graph theory is an endless source of easily stated yet very hard problems. Many of these
problems require algorithms; given a graph, one may ask if the graph has a certain prop-
erty, and an algorithm is to provide the answer. Since graphs are widely used as models
of real phenomena, it is important to discover
e~cient
algorithms for answering graph-
theoretic questions. This paper presents an efficient algorithm to determine whether a
graph G can be embedded (without any crossing edges) in the plane.
The planarity algorithm may be viewed as an iterative version of a recursive method
originally proposed by Auslander and Patter [1] and correctly formulated by Goldstein
[2]. The algorithm uses
depth-first search
to order the calculations and thereby achieve
efficiency. Depth-first search, or backtracking, has been widely used for finding solu-
tions to problems in combinatorial theory and artificial intelligence [3, 4]. Recently this
type of search has been used to construct efficient algorithms for solving several problems
in graph theory, including finding biconnected components [5, 6], finding triconnected
components [7, 81, finding strongly connected components [61, finding dominators [9],
and determining whether a directed graph is reducible [10, 11].
In order to analyze the theoretical efficiency of the planarity algorithm, a random ac-
cess computer model is used. Data storage and retrieval, arithmetic operations, compari-
sons, and logical operations are assumed to require fixed times. A memory cell is allowed
to hold integers whose absolute value is bounded by kV for some constant k, where V is
the number of vertices in the problem graph. Cook [12] describes an exact computer model
along these lines. If f and g are functions of x, we say
"f(x)
is
O(g(x))"
if, for some
constants kI and k2,
If(x) I -< ki I g(x) I + k2
for all x. Within this framework, the
planarity algorithm has 0 (V) time and space bounds and is optimal to within a constant
factor.
The practical efficiency of the algorithm was measured by implementing it in ALGOL
Copyright (~) 1974, Association for Computing Machinery, Inc. General permission to republish,
but not for profit, all or part of this material is granted provided that ACM's copyright notice is
given and that reference is made to the publication, to its date of issue, and to the fact that reprinting
privileges were granted by permission of the Association for Computing Machinery.
This research was supported by the Hertz Foundation, the NSF, and the Office of Naval Research
under grants #N-0O014-A-Ol12-0057 and #N-00014-67-A-0077-0021.
Authors' present addresses: J. Hopcroft, Department of Computer Science, Cornell University,
Ithaca, NY 14850; R. Tarjan, Department of Electrical Engineering, University of California,
Berkeley, CA 94720.
Journal of the Association for Computing Machinery, Vol. 21, No. 4, October 1974, pp. 549-568.