Conference PaperPDF Available

# A linear time implementation of SPQR-trees

Authors:

## Abstract and Figures

The data structure SPQR-tree represents the decomposition of a biconnected graph with respect to its triconnected components. SPQR-trees have been introduced by Di Battista and Tamassia [8] and, since then, became quite important in the field of graph algorithms. Theoretical papers using SPQR-trees claim that they can be implemented in linear time using a modification of the algorithm by Hopcroft and Tarjan [15] for decomposing a graph into its triconnected components. So far no correct linear time implementation of either triconnectivity decomposition or SPQR-trees is known to us. Here, we show the incorrectness of the Hopcroft and Tarjan algorithm [15], and correct the faulty parts. We describe the relationship between SPQR-trees and triconnected components and apply the resulting algorithm to the computation of SPQR-trees. Our implementation is publically available in AGD [1].
Content may be subject to copyright.
A Linear Time Implementation of SPQR-Trees?
Carsten Gutwenger1and Petra Mutzel2
1Max-Planck-Institut f¨ur Informatik
Saarbr¨ucken, Germany, gutwenge@mpi-sb.mpg.de
Abstract. The data structure SPQR-tree represents the decomposition
of a biconnected graph with respect to its triconnected components.
SPQR-trees have been introduced by Di Battista and Tamassia [8] and,
since then, became quite important in the ﬁeld of graph algorithms.
Theoretical papers using SPQR-trees claim that they can be implemen-
ted in linear time using a modiﬁcation of the algorithm by Hopcroft and
Tarjan [15] for decomposing a graph into its triconnected components.
So far no correct linear time implementation of either triconnectivity
decomposition or SPQR-trees is known to us. Here, we show the incor-
rectness of the Hopcroft and Tarjan algorithm [15], and correct the faulty
parts. We describe the relationship between SPQR-trees and triconnec-
ted components and apply the resulting algorithm to the computation
of SPQR-trees. Our implementation is publically available in AGD [1].
1 Introduction
The data structure SPQR-tree represents the decomposition of a biconnected
graph with respect to its triconnected components. SPQR-trees have been intro-
duced by Di Battista and Tamassia [8] in a static and in a dynamic environment.
In [8,10], the authors use SPQR-trees in order to represent the set of all planar
embeddings of a planar biconnected graph.
Since then, SPQR-trees evolved to an important data structure in the ﬁeld
of graph algorithms. Many linear time algorithms that work for triconnected
graphs only can be extended to work for biconnected graphs using SPQR-trees
(e.g., [4,17]). Often it is essential to represent the set of all planar embeddings
of a planar graph, e.g. in order to optimize a speciﬁc criteria over all planar
embeddings [14,21,3,5], or for testing cluster planarity [18,6]. In a dynamic envi-
ronment, SPQR-trees are useful for a variety of on-line graph algorithms dealing
with triconnectivity, transitive closure, minimum spanning tree, and planarity
testing [2]. Here, we restrict our attention to the static environment.
In the theoretical papers (e.g., [8,9,10]), the authors suggest to construct the
data structure SPQR-tree in linear time “using a variation of the algorithm of [15]
for ﬁnding the triconnected components of a graph...[10]”. So far, to our kno-
wledge, no correct linear time implementation is publically available. The only
correct implementation of SPQR-trees we are aware of is part of GDToolkit [12],
?Partially supported by DFG-Grant Mu 1129/3-1, Forschungsschwerpunkt “Eﬃziente
Algorithmen f¨ur diskrete Probleme und ihre Anwendungen”.
J. Marks (Ed.): GD 2000, LNCS 1984, pp. 77–90, 2001.
c
Springer-Verlag Berlin Heidelberg 2001
78 C. Gutwenger and P. Mutzel
where SPQR-trees are used in connection with a branch-and-bound algorithm
to compute an orthogonal drawing of a biconnected planar graph with the mi-
nimum number of bends. However, this implementation does not run in linear
time [11].
Here, we present a linear time implementation of the data structure SPQR-
tree. We show the relationship between SPQR-trees and triconnected compo-
nents, and show the incorrectness of the algorithm presented in [15] for decom-
posing a graph into its triconnected components. We develop a correct algorithm
for triconnectivity decomposition by correcting and replacing the faulty parts in
[15], and apply it to the computation of SPQR-trees. Our implementation (in a
re-usable form) is publically available in AGD [1] (see Section 6).
The paper is structured as follows. The basics of SPQR-trees and triconnected
components are described in Section 3. The algorithm for computing SPQR-trees
and triconnectivity decomposition is described in Section 4, and the faulty parts
of the Hopcroft and Tarjan algorithm are shown in Section 5, where we also point
out the corrections we have made. We have carefully tested our implementation.
Computational results concerning running time are described in Section 6.
2 Preliminaries
Let G=(V,E)beanundirected multi-graph, that is, Vis a set of vertices and
Eis a multi-set of unordered pairs (u, v) with u, v V. An edge (v, v) is called a
self-loop. If an edge (u, v)Eoccurs more than once in E, it is called a multiple
edge.Gis called simple, if it contains neither self-loops nor multiple edges. If E0
is a set of edges, V(E0) denotes the set of all vertices incident to at least one
edge in E0.Apath p:v
win Gis a sequence of vertices and edges leading
from vto w. A path is simple if all its vertices are distinct. If p:v
wis a
simple path, then pplus the edge (w, v)isacycle.
An undirected multi-graph G=(V,E)isconnected if every pair v, w Vof
vertices in Gis connected by a path. A connected multi-graph Gis biconnected
if for each triple of distinct vertices v,w, a, there is a path p:v
wsuch that a
is not on p. Let G=(V, E) be a biconnected multi-graph and a, b V.Ecan be
divided into equivalence classes E1,...,E
ksuch that two edges which lie on a
common path not containing any vertex of {a, b}except as an endpoint are in the
same class. The classes Eiare called the separation classes of Gwith respect to
{a, b}. If there are at least two separation classes, then {a, b}is a separation pair
of Gunless (i) there are exactly two separation classes, and one class consists of
a single edge, or (ii) there are exactly three classes, each consisting of a single
edge. If Gcontains no separation pair, Gis called triconnected.
Atree Tis a directed graph whose underlying undirected graph is connected,
such that there is exactly one vertex (called the root ) having no incoming edges
and every other vertex has exactly one incoming edge. An edge in Tfrom vto w
is denoted with vw. If there is a (directed) path from vto w, we write v
w.
If vw,vis the parent of w, and wachild of v.Ifv
w,vis an ancestor
of w, and wadescendant of v. Every vertex is an ancestor and a descendant of
A Linear Time Implementation of SPQR-Trees 79
itself. If Gis a directed multi-graph, a tree Tis a spanning tree of Gif Tis a
subgraph of Gand Tcontains all vertices in G.
Apalm tree Pis a directed multi-graph such that each edge in Pis a either
a tree arc (denoted with vw) or a frond (denoted with vw) satisfying the
following properties:
(i) The subgraph Tconsisting of all tree arcs is a spanning tree of P.
(ii) If vw, then w
v.
3 SPQR-Trees and Triconnected Components
Let G=(V, E) be a biconnected multi-graph, {a, b}a separation pair of G, and
E1,...,E
kthe separation classes of Gwith respect to {a, b}. Let E0=S
i=1 Ei
and E00 =Sk
i=+1 Eibe such that |E0|≥2 and |E00|≥2. The two graphs
G0=(V(E0),E0∪{e}) and G00 =(V(E00),E00 ∪{e}) are called split graphs of G
with respect to {a, b}, where e=(a, b) is a new edge. Replacing a multi-graph G
by two split graphs is called splitting G. Each split graph is again biconnected.
The edge eis called virtual edge and identiﬁes the split operation.
Suppose Gis split, the split graphs are split, and so on, until no more split
operations are possible. The resulting graphs are called the split components of
G. Each of them is a set of three multiple edges (triple bond ), or a cycle of length
three (triangle), or a triconnected simple graph. The split components are not
necessarily unique.
Lemma 1. Let G=(V,E)be a multi-graph.
(i) Each edge in Eis contained in exactly one, and each virtual edge in exactly
two split components.
(ii) [15] The total number of edges in all split components is at most 3|E|−6.
Let G1=(V1,E
1) and G2=(V2,E
2) be two split components containing
the same virtual edge e. The graph G0=(V1V2,(E1E2)\{e}) is called a
merge graph of G1and G2. Replacing two components G1and G2by a merge
graph of G1and G2is called merging G1and G2. The triconnected components
of Gare obtained from its split components by merging the triple bonds into
maximal sets of multiple edges (bonds) and the triangles into maximal simple
cycles (polygons).
Lemma 2. [19,15] The triconnected components of Gare unique.
Triconnected components of graphs are closely related to SPQR-trees. SPQR-
trees were originally deﬁned in [8] for planar graphs only. Here, we cite the more
general deﬁnition given in [9], that also applies to not necessarily planar graphs.
Let Gbe a biconnected graph. A split pair of Gis either a separation pair or
a pair of adjacent vertices. A split component of a split pair {u, v}is either an
edge (u, v) or a maximal subgraph Cof Gsuch that {u, v}is not a split pair of
C. Let {s, t}be a split pair of G.Amaximal split pair {u, v}of Gwith respect
80 C. Gutwenger and P. Mutzel
to {s, t}is such that, for any other split pair {u0,v
0}, vertices u,v,s, and tare
in the same split component.
Let e=(s, t) be an edge of G, called the reference edge. The SPQR-tree T
of Gwith respect to eis a rooted ordered tree whose nodes are of four types:
S, P, Q, and R. Each node µof Thas an associated biconnected multi-graph,
called the skeleton of µ. Tree Tis recursively deﬁned as follows:
Trivial Case: If Gconsists of exactly two parallel edges between sand t, then
Tconsists of a single Q-node whose skeleton is Gitself.
Parallel Case: If the split pair {s, t}has at least three split components G1,...,
Gk, the root of Tis a P-node µ, whose skeleton consists of kparallel edges
e=e1,...,e
kbetween sand t.
Series Case: Otherwise, the split pair {s, t}has exactly two split components,
one of them is e, and the other one is denoted with G0.IfG0has cutvertices
c1,...,c
k1(k2) that partition Ginto its blocks G1,...,G
k, in this
order from sto t, the root of Tis an S-node µ, whose skeleton is the cycle
e0,e
1,...,e
k, where e0=e,c0=s,ck=t, and ei=(ci1,c
i)(i=1,...,k).
Rigid Case: If none of the above cases applies, let {s1,t
1},...,{sk,t
k}be the
maximal split pairs of Gwith respect to {s, t}(k1), and, for i=1,...,k,
let Gibe the union of all the split components of {si,t
i}but the one contai-
ning e. The root of Tis an R-node, whose skeleton is obtained from Gby
replacing each subgraph Giwith the edge ei=(si,t
i).
Except for the trivial case, µhas children µ1,...,µ
k, such that µiis the root
of the SPQR-tree of Gieiwith respect to ei(i=1,...,k). The endpoints
of edge eiare called the poles of node µi. The virtual edge of node µiis edge
eiof skeleton of µ. Tree Tis completed by adding a Q-node, representing the
reference edge e, and making it the parent of µso that it becomes the root.
Each edge in Gis associated with a Q-node in T. Each edge eiin skeleton
of µis associated with the child µiof µ. It is possible to root Tat an arbitrary
Q-node µ0, resulting in an SPQR-tree with respect to the edge associated with µ0
[9]. In our implementation, we use a slightly diﬀerent, but equivalent, deﬁnition
of SPQR-tree. We omit Q-nodes and distinguish between real edges and virtual
edges in the skeleton graphs instead. An edge in the skeleton of µwhich is
associated with a Q-node in the original deﬁnition is a real edge that is not
associated with a child of µ, all other skeleton edges are virtual edges associated
with a P-, S-, or R-node. Using this modiﬁed deﬁnition, we can show that the
skeleton graphs are the unique triconnected components of G:
Theorem 1. Let Gbe a biconnected multi-graph and Tits SPQR-tree.
(i) The skeleton graphs of Tare the triconnected components of G. P-nodes
correspond to bonds, S-nodes to polygons, and R-nodes to triconnected simple
graphs.
(ii) There is an edge between two nodes µ, ν ∈T if and only if the two corre-
sponding triconnected components share a common virtual edge.
(iii) The size of T, including all skeleton graphs, is linear in the size of G.
A Linear Time Implementation of SPQR-Trees 81
Proof. (sketch) We remark that if {u, v}is a separation pair, the split compo-
nents of {u, v}are the separation classes with respect to {u, v}. In the parallel, se-
ries, and rigid case of the deﬁnition of SPQR-tree, subgraphs G1,...,G
kare con-
sidered. Assume that G1,...,G
contains more than one edge, and G+1,...,G
k
contains exactly one edge. In each of the three cases, the recursive decomposition
step can be realized by performing split operations, each splitting oﬀ one Gi,
1iand introducing a new virtual edge e0in the skeleton of node µand the
skeleton of a child µiof µ. since e0remains in the skeleton of µiin subsequent
steps, part (ii) of the theorem follows.
The ﬁnal skeleton graphs are each either a polygon, a bond, or a simple
triconnected graph, and no two polygons, and no two bonds share a common
virtual edge. Thus, the skeleton graphs are the unique triconnected components
of Gproving part (i). The last part of the theorem follows directly from (i) and
Lemma 1. ut
4 The Algorithm
Let Gbe a biconnected multi-graph without self-loops. According to Theorem 1,
it suﬃces to compute the triconnected components of G, which give us enough
information to build the SPQR-tree of G. We correct the faulty parts in the
algorithm by Hopcroft and Tarjan [15] and apply this modiﬁed algorithm for
computing the triconnected components. We focus on the computation of split
pairs, because the description of this part in [15] is not only confusing but con-
tains also severe errors. For an overview of the Hopcroft and Tarjan algorithm,
please refer to [15] or [13].
4.1 Computing SPQR-Trees
Input to the algorithm is a biconnected multi-graph G=(V, E) and a reference
edge er. In the ﬁrst step, bundles of multiple edges are replaced by a new virtual
edge as shown in Alg. 1. This creates a set of bonds C1,...,C
kand results in
a simple graph G0. The required sorting of the edges in line 1.1 can be done in
O(|V|+|E|) time using bucket sort two times. Firstly according to the endpoint
with lower index, and secondly to the one with higher index, where we assume
that vertices have unique indices in the range 1,...,|V|. The for-loop in line 1.2
iterates over all edges, so Alg. 1 has running time O(|V|+|E|).
Algorithm 1: Split oﬀ multiple edges
1.1 Sort edges such that all multiple edges come after each other
1.2 for each maximal bundle of multiple edges e1,...,e
with 2do
let e1,...,e
be edges between vand w
replace e1,...,e
by a new edge e0=(v, w)
create a new component C={e1,...,e
,e
0}
end
82 C. Gutwenger and P. Mutzel
The second step ﬁnds the split components Ck+1,...,C
mof G0. The pro-
cedure is presented in detail in the next subsection. The triconnected compo-
nents of the input graph Gare created by partially reassembling the components
C1,...,C
m. As long as two bonds or two polygons Ciand Cjcontaining the same
virtual edge exist, Ciand Cjare merged. This is shown in Alg. 2. Removed com-
ponents are marked as empty. The forall-loop in line 2.1 steps over all edges in
Ci, i.e. those added to Ciduring the loop. The test in line 2.1 can be done in
constant time by precomputing for each virtual edge ethe two components to
which ebelongs. We represent the edges in a component Ciby a list of edges,
which allows to implement the set operations in lines 2.3 and 2.4 in constant
time. According to Lemma 1, the total number of edges in all components is
O(|E|), so Alg. 2 can also be implemented in time O(|V|+|E|).
Algorithm 2: Build triconnected components
for i:= 1 to mdo
if Ci6=and Ciis a bond or a polygon then
2.1 forall eCido
2.2 if there exists j6=iwith eCjand type(Ci)=type(Cj)then
2.3 Ci:= (CiCj)\{e}
2.4 Cj:=
end
od
end
end
The preceding steps give enough information to build the SPQR-tree Tof
G. Applying Theorem 1, it is easy to construct the unrooted version of T. Since
we omit Q-nodes in our representation, we root Tat the node whose skeleton
contains the reference edge er. During the construction, we also create cross links
between each tree edge µνin Tand the two corresponding virtual edges in
skeleton of µand skeleton of ν.
4.2 Finding Separation Pairs
Suppose we have a palm tree Pfor the simple, biconnected graph G0=(V,E0),
and the vertices of G0are numbered 1,...,|V|. In the following, we identify
vertices with their numbers. We introduce the following notation:
lowpt1(v) = min {v}∪{w|v
w}
lowpt2(v) = min {v}∪{w|v
w}\{lowpt1(v)}
That is, lowpt1(v)isthelowest vertex reachable by traversing zero or more tree
arcs followed by one frond of P(or vif no such vertex exists), and lowpt2(v)is
the second lowest vertex reachable this way (or vif no such vertex exists).
A Linear Time Implementation of SPQR-Trees 83
We denote with Adj (v) the ordered (non-cyclic) adjacency list of a vertex
v, and with D(v) the set of descendants of v. We seek for a numbering of the
vertices and ordering of the edges in the adjacency lists satisfying the following
properties:
(P1) the root of Pis 1.
(P2) if vVand w1,...,w
nare the children of vin Paccording to the ordering
in Adj (v), then wi=w+|D(wi+1 )...D(wn)|+1.
(P3) the edges ein Adj (v) are in ascending order according to lowpt1(w)if
e=vw,orwif e=vw, respectively.
Let w1,...,w
nbe the children of vwith lowpt1(wi)=uin the order given
by Adj (v). Then there exists an i0such that lowpt 2(wi)<vfor 1 ii0,
and lowpt2(wj)vfor i0<jn.IfvuE0, then vucomes in
It is shown in [15], how to compute such a numbering of the vertices and ordering
of the adjacency lists in linear time. Unlike [15], we demand that a frond vw,
if contained in E0, must come between vwi0and vwi0+1 in Adj (v). This
can easily be done by adapting the sorting function φused in [15]:
φ(e)=
3lowpt1(w)ife=vwand lowpt2(w)<v
3w+1 ife=vw
3lowpt1(w)+2if e=vwand lowpt 2(w)v
The required ordering can be obtained by sorting the edges according to their
φ-values using bucket sort. Using ordering φand procedure PATHSEARCH as
suggested in [15] will not recognize all multiple edges and thus not correctly
compute the split components of G0.
Suppose we perform a depth-ﬁrst-search on G0using the ordering of the edges
in the adjacency lists. This divides G0into a set of paths consisting of zero or
more tree arcs followed by one frond. The ﬁrst path starts at vertex 1 and a
path ends, when the ﬁrst frond on the path is reached (see Fig. 1). Each path
ends at the lowest possible vertex, and has only its initial and terminal vertex
in common with previously traversed paths. From each such path p:v
w,we
can form a cycle by adding the tree path from w
vto p(compare [15,16]).
Example 1. Fig. 1 shows a palm tree with a numbering that satisﬁes (P1)-(P3).
The edges are numbered according to the generated paths. The generated paths
are
1: 1 2313 17:129
2: 13 28:1011 8
3: 3 419:119
4: 4 581 10: 5 674
5: 8 910 12 1 11: 7 5
6: 12 8 12: 6 4
We need one more deﬁnition: unis a ﬁrst descendant of u0if u0··· un
and each uiui+1 is the ﬁrst edge in Adj (ui). In the sequel, we consider a palm
84 C. Gutwenger and P. Mutzel
12
1
11
4
3
10
2
6
8
13
7
5
9
10
1
1
1
1
6
10
10
3
3
8
8
12
4
4
4
7
11
2
5
5
5
5
9
Fig. 1. Palm tree with numbered vertices and generated paths.
tree Psatisfying (P1)-(P3). The following lemma gives us three easy-to-check
conditions for separation pairs.
Lemma 3. (Lemma 13 in [15]) Let G=(V,E)be a biconnected graph and a, b
be two vertices in Gwith a<b. Then {a, b}is a separation pair if and only if
one of the following conditions holds.
Type-1 Case: There are distinct vertices r6=a, b and s6=a, b such that br,
lowpt1(r)=a, lowpt2(r)b, and sis not a descendant of r.
Type-2 Case: There is a vertex r6=bsuch that ar
b,bis a ﬁrst descendant
of r,a6=1, every frond xywith rx<bhas ay, and every frond
xywith a<y<band bw
xhas lowpt1(w)a.
Multiple Edge Case: (a, b)is a multiple edge of Gand Gcontains at least four
edges.
Example 2. Consider the palm tree from Fig. 1. We have the following separation
pairs:
type-1 pairs: (1,4),(1,5),(4,5),(1,8),(1,3)
type-2 pairs: (4,8),(8,12)
A Linear Time Implementation of SPQR-Trees 85
4.3 Finding Split Components
During the algorithm, we maintain a graph Gcand a palm tree Pcof Gc.We
denote with deg(v) the degree of vin Gc, with vwa tree arc in Pc, with
vwa frond in Pc, with pare nt (v) the parent of vin Pc, and with ND(v) the
number of descendants of vin Pc. Each time we identify a split component C,we
split it oﬀ, and Gcand Pcare updated. We use the following update functions:
C:= new component(e1,...,e
): a new component C={e1,...,e
}is created,
and e1,...,e
are removed from Gc.
C:= C∪{e1,...,e
}: the edges e1,...,e
are added to Cand removed from Gc.
e0:= new virtual edge(v, w, C): a new virtual edge e0=(v, w) is created and
make tree edge(e, v w): makes edge e=(v, w) a new tree edge in Pc.
Moreover, we deﬁne the access functions
ﬁrstChild(v) = ﬁrst child of vin Pcaccording to Adj (v).
high(w)=0ifF(w)=
source vertex of ﬁrst visited edge in F(w) otherwise
where F(w)={v|vwEc}, and we use two stacks for which the usual
functions push,pop, and top are deﬁned:
ESTACK contains already visited edges that are not yet assigned to a split com-
ponent.
TSTACK contains triples (h, a, b) (or a special end-of-stack marker EOS ), such
that {a, b}is a potential type-2 separation pair, and his the highest num-
bered vertex in the component that would be split oﬀ.
The algorithm starts by calling the recursive procedure PathSearch for vertex
1, the root vertex of P(see Alg. 3). When returning from the call, the edges
belonging to the last split component are on ESTACK.
Algorithm 3: Find split components
TSTACK.push(EOS)
PathSearch(1)
let e1,...,e
be the edges on ESTACK
3.1 C:= new component(e1,...,e
)
Procedure PathSearch is shown in Alg. 4. The testing for separation pairs
applying Lemma 3 is depicted separately in Alg. 5 for type-2 and in Alg. 6 for
type-1 separation pairs1. For a detailed description of the algorithm, please refer
to [15,13]. In order to achieve linear running time, we set up the following data
structures:
1The algorithm will not ﬁnd all separation pairs, but only the separation pairs needed
for dividing the graph into its split components
86 C. Gutwenger and P. Mutzel
Algorithm 4: PathSearch(v)
if e=vwthen
if estarts a path then
pop all (h, a, b)with a>lowpt1(w)from TSTACK
if no triples deleted then
TSTACK.push(w+ND(w)1,lowpt 1(w),v)
else
y:= max{h|(h, a, b)deleted from TSTACK }
let (h, a, b)be last triple deleted
TSTACK.push(max(y, w +ND (w)1),lowpt 1(w),b)
end
TSTACK.push(EOS)
end
PathSearch(w)
ESTACK.push(vw)
check for type-2 pairs
check for a type-1 pair
if estarts a path then
remove all triples on TSTACK down to and including EOS
end
4.1 while (h, a, b)on TSTACK has a6=vand b6=vand high(v)>hdo
TSTACK.pop()
od
else
let e=vw
if estarts a path then
pop all (h, a, b)with a>wfrom TSTACK
if no triples deleted then
TSTACK.push(v, w, v)
else
y:= max{h|(h, a, b)deleted from TSTACK }
let (h, a, b)be last triple deleted
TSTACK.push(y, w, b)
end
end
if w=pare nt (v)then
C:= new component(e, w v)
e0:= new virtual edge(w, v, C)
make tree edge(e0,w v)
else
ESTACK.push(e)
end
end
od
A Linear Time Implementation of SPQR-Trees 87
Algorithm 5: check for type-2 pairs
while v6=1and (((h, a, b)on TSTACK has a=v)or (deg(w)=2and
ﬁrstChild(w)>w)) do
if a=vand parent(b)=athen
TSTACK.pop()
else
eab := nil
if deg(w)=2and ﬁrstChild(w)>wthen
C:= new component()
remove top edges (v, w)and (w, b)from ESTACK and add to C
e0:= new virtual edge(v, x, C )
if ESTACK.top() =(v, b)then eab := ESTACK.pop()
else
(h, a, b):=TSTACK.pop()
C:= new component()
while (x, y)on ESTACK has axhand ayhdo
if (x, y)=(a, b)then eab := ESTACK.pop()
else C:= C∪{ESTACK.pop() }
od
e0:= new virtual edge(a, b, C)
end
if eab 6=nil then
C:= new component(eab,e
0)
e0:= new virtual edge(v, b, C )
end
ESTACK.push(e0);make tree edge(e0,v b);w:= b
end
od
Algorithm 6: check for a type-1 pair
6.1 if lowpt2(w)vand lowpt1(w)<v and (pare nt (v)6=1or vis adjacent to
a not yet visited tree arc)then
C:= new component()
while (x, y)on ESTACK has wx<w+ND (w)or wy<w+ND (w)
do
C:= C∪{ESTACK.pop() }
od
e0:= new virtual edge(v, lowpt1(w),C)
if ESTACK.top() =(v, lowpt 1(w)) then
C:= new component(ESTACK.pop(),e0)
e0:= new virtual edge(v, lowpt1(w),C)
end
if lowpt1(w)6=pare nt (v)then
ESTACK.push(e0)
make tree edge(e0,lowpt1(w)v)
else
C:= new component(e0,lowpt1(w)v)
e0:= new virtual edge(lowpt1(w),v,C)
make tree edge(e0,lowpt1(w)v)
end
end
88 C. Gutwenger and P. Mutzel
The palm tree Pis represented by arrays PARENT[v],TREE ARC[v] (the
tree arc entering v), and TYPE[e] (tree arc or frond).
The values lowpt1(v), lowpt 2(v), and ND (v) are precomputed. It is not ne-
cessary to update them.
An array DEGREE[v] contains the degree of vGc. It is updated each time
an edge is added to or removed from Gc.
In order to compute ﬁrstChild(v), we update the adjacency lists each time
an edge is added to or removed from Gc.
In order to compute high(v), we precompute the list of fronds viwending
at win the order they are visited. When a frond is removed from or added
to Gc, the respective list is updated.
We precompute an array START[e] which is true iﬀ estarts a path.
The test if “vis adjacent to a not yet visited tree arc” in line 6.1 can be
done by simply counting the visited adjacent tree arcs.
5 Corrections on the Hopcroft and Tarjan Algorithm
Procedure SPLIT in [15] does not correctly split a graph into its split compo-
nents. We summarize the important changes we have made in our algorithm:
The sorting function φhad to be modiﬁed as described in subsection 4.2 in
order to identify all multiple edges.
The creation of the last split component (line 3.1) was missing.
The condition in line 4.1 was changed. The original condition could remove
triples from TSTACK corresponding to real type-2 separation pairs. Such a
separation pair could not be recognized by the original SPLIT procedure.
The condition in line 6.1 was changed. The original condition could incor-
rectly identify separation pairs after the graph had been modiﬁed.
The updates for ﬁrstChild (v) (which is A1(v) in [15]) and DEGREE(v) were
not suﬃcient.
high(w) (which is HIGHPT(w) in [15]) was not updated, which is not correct.
It is necessary to update HIGHPT dynamically, when Gcis modiﬁed. We
replaced HIGHPT(w) by a list of fronds ending at w, which is updated as
Gcchanges.
6 Computational Experiments
Our implementation is based on LEDA [20] and made publically available in
AGD [1]. We tested our implementation with generated planar and non-planar
biconnected graphs, and the benchmark graphs collected by Di Battista et al. [7]
ranging from 10 to 100 vertices. A planar biconnected graph with nvertices and
medges is generated by nrandomly chosen split-edge and mnsplit face ope-
rations. A general biconnected graph is generated by creating a random graph
Gand making Gbiconnected by augmenting edges. The computed SPQR-trees
are automatically checked with several consistency and plausibility tests. The
A Linear Time Implementation of SPQR-Trees 89
average running times are depicted in Fig. 2. The x-axis shows the number of
vertices, and the y-axis the running time in seconds. The left side shows the
results for generated graphs with nvertices and medges applying the algorithm
to 100 test instances each. Even very large instances with 40000 edges could be
solved within less than 4 seconds. The right side shows the results for the bench-
mark graphs applying the algorithm to each biconnected component containing
at least three edges. Graphs with 100 vertices took about 0.02 seconds.
Recently, Gutwenger, Mutzel, and Weiskircher [14] have presented a linear
time algorithm for solving the one edge insertion problem optimally (minimum
number of crossings) over all combinatorial embeddings. Their algorithm requires
to compute SPQR-trees for some biconnected components of a planar input
graph. In their tests, they also used the benchmark graphs from [7] and applied
our implementation of SPQR-trees. The longest running time for a graph with
100 vertices was 1.15 seconds, where 38 edges had to be inserted.
0
0.5
1
1.5
2
2.5
3
3.5
4
0 2000 4000 6000 8000 10000 12000 14000 16000 18000 20000
random planar biconnected, m=2n
random biconnected, m=10n
0
0.002
0.004
0.006
0.008
0.01
0.012
0.014
0.016
0.018
0.02
0.022
10 20 30 40 50 60 70 80 90 100
benchmark graphs by Di Battista et al.
Fig. 2. Average running times (system conﬁguration: Pentium II, 400 MHz, 128MB
RAM)
References
[1] AGD User Manual (Version 1.1.2), Feb. 2000. Max-Planck-Institut Saarbr¨ucken,
http://www.mpi-sb.mpg.de/AGD/.
[2] G. Di Battista and R. Tamassia. On-line graph algorithms with SPQR-trees. In
M. S. Paterson, editor, Proc. of the 17th International Colloqium on Automata,
Languages and Prog ramming (ICALP), volume 443 of Lecture Notes in Computer
Science, pages 598–611. Springer-Verlag, 1990.
[3] P. Bertolazzi, G. Di Battista, and W. Didimo. Computing orthogonal drawings
with the minimum number of bends. In Proc. 5th Workshop Algorithms, Data
Struct., volume 1272 of Lecture Notes in Computer Science, pages 331–344, 1998.
[4] P. Bertolazzi, G. Di Battista, G. Liotta, and C. Mannino. Optimal upward pla-
narity testing of single-source digraphs. SIAM J. Comput., 27(1):132–169, 1998.
90 C. Gutwenger and P. Mutzel
[5] D. Bienstock and C. L. Monma. On the complexity of embedding planar graphs
to minimize certain distance measures. Algorithmica, 5(1):93–109, 1990.
[6] Elias Dahlhaus. A linear time algorithm to recognize clustered planar graphs and
its parallelization. In C. L. Lucchesi and A. V. Moura, editors, LATIN ’98: Theo-
retical Informatics, Third Latin American Symposium, volume 1380 of Lecture
Notes in Computer Science, pages 239–248. Springer-Verlag, 1998.
[7] G. Di Battista, A. Garg, G. Liotta, R. Tamassia, and F. Vargiu. An experimental
comparision of four graph drawing algorithms. Comput. Geom. Theory Appl.,
7:303–326, 1997.
[8] G. Di Battista and R. Tamassia. Incremental planarity testing. In Proc. 30th
IEEE Symp. on Foundations of Computer Science, pages 436–441, 1989.
[9] G. Di Battista and R. Tamassia. On-line maintanance of triconnected components
with SPQR-trees. Algorithmica, 15:302–318, 1996.
[10] G. Di Battista and R. Tamassia. On-line planarity testing. SIAM J. Comput.,
25(5):956–997, 1996.
[11] W. Didimo. Dipartimento di Informatica e Automazione, Universita di Roma Tre,
Rome, Italy, Personal Communication.
[12] GDToolkit Online Documentation. See http://www.dia.uniroma3.it/˜gdt.
[13] C. Gutwenger and P. Mutzel. A linear time implementation of SPQR-trees. Tech-
nical report, Technische Universit¨at Wien, 2000. To appear.
[14] C. Gutwenger, P. Mutzel, and R. Weiskircher. Inserting an edge into a planar
graph. In Proceedings of the Twelfth Annual ACM-SIAM Symposium on Discrete
Algorithms (SODA ’01). ACM Press, 2001. To appear.
[15] J. E. Hopcroft and R. E. Tarjan. Dividing a graph into triconnected components.
SIAM J. Comput., 2(3):135–158, 1973.
[16] J. E. Hopcroft and R. E. Tarjan. Eﬃcient planarity testing. Journal of the ACM,
21:549–568, 1974.
[17] G. Kant. Drawing planar graphs using the canonical ordering. Algorithmica,
Special Issue on Graph Drawing, 16(1):4–32, 1996.
[18] T. Lengauer. Hierarchical planarity testing. Journal of the ACM, 36:474–509,
1989.
[19] S. MacLaine. A structural characterization of planar combinatorial graphs. Duke
Math. J., 3:460–472, 1937.
[20] K. Mehlhorn and S. N¨aher. The LEDA Platform of Combinatorial and Geometric
Computing. Cambridge University Press, 1999. to appear.
[21] P. Mutzel and R. Weiskircher. Optimizing over all combinatorial embeddings
of a planar graph. In G. Cornu´ejols, R. Burkard, and G. Woeginger, editors,
Proceedings of the Seventh Conference on Integer Programming and Combinatorial
Optimization (IPCO), volume 1610 of LNCS, pages 361–376. Springer Verlag,
1999.
... In 19,20 , it has been identified that a port-wise decomposition of electrical circuits can also be achieved in an algorithmic manner. The idea is to make use of the so-called SPQR-tree decomposition algorithm, which was first invented by Hopcraft and Tarjan 21 , later formally established by Tamassia and Di Battista 22 , and finally corrected and enhanced by Gutwenger and Mutzel 23 . The SPQR-tree is a graph data structure, which provides a tree representation of the input graph in terms of its split components. ...
... The idea of the SPQR-tree decomposition is to find separation pairs and split the graph into as many split components as possible. The SPQR-tree, itself, is a hierarchical representation of the split components of a biconnected graph 23 . To achieve this representation, one must first find all split components within the graph and then interconnect every two split components sharing a common virtual edge. ...
... Comparing the graph representation (input graph) itself to the split components resulting from the application of the algorithm, we see that the decomposition becomes quite simple, as we now only need to identify the  component. Note, the  component is already found during a preprocessing step of the SPQR-algorithm 23 . As a result, the algorithm needs to deal with less -type components, as multi-ports are not represented by sophisticated replacement graphs anymore. ...
Article
Full-text available
We report on a systematic method for the port-wise decomposition of electrical networks. Our method exploits the SPQR-tree decomposition as an algorithmic way for decomposing a given circuit into a maximal set of one-and multi-ports. We provide a solution for representing multi-ports by suitable replacement graphs, such that they are encapsulated not decomposed or processed by the SPQR-algorithm. Contrary to current methods, our replacement graphs are not sophisticated but rather simple, which, in general, enhances the performance of the algorithm, when it comes to decomposing large electrical networks containing multi-ports. Some electrical devices, such as transistors or op-amps, are commonly described in terms of their terminals rather than their ports. Thus, we cover the application of the template-based approach to 3-terminal devices. Lastly, we make use of the new decomposition method for the emulation of a wave digital filter.
... All embeddings of pert(μ) can be described by a permutation of the parallel virtual edges in each P-node in T μ and a flip of the skeleton of each R-node in T μ . SPQR-tree T is unique, and can be computed in linear time [17]. ...
... To complete the proof of the theorem, it remains to discuss the time complexity of our algorithm. The construction of the SPQR-tree can be done in O(n) time [17]. Then, at each step of the algorithm, we consider a node μ of T and we perform a set of operations in time linear to the size of skel(μ). ...
Article
Full-text available
Bitonic st -orderings for st -planar graphs were introduced as a method to cope with several graph drawing problems. Notably, they have been used to obtain the best-known upper bound on the number of bends for upward planar polyline drawings with at most one bend per edge in polynomial area. For an st -planar graph that does not admit a bitonic st -ordering, one may split certain edges such that for the resulting graph such an ordering exists. Since each split is interpreted as a bend, one is usually interested in splitting as few edges as possible. While this optimization problem admits a linear-time algorithm in the fixed embedding setting, it remains open in the variable embedding setting. We close this gap in the literature by providing a linear-time algorithm that optimizes over all embeddings of the input st -planar graph. The best-known lower bound on the number of required splits of an st -planar graph with n vertices is $$n-3$$ n - 3 . However, it is possible to compute a bitonic st -ordering without any split for the st -planar graph obtained by reversing the orientation of all edges. In terms of upward planar polyline drawings in polynomial area, the former translates into $$n-3$$ n - 3 bends, while the latter into no bends. We show that this idea cannot always be exploited by describing an st -planar graph that needs at least $$n-5$$ n - 5 splits in both orientations. We provide analogous bounds for graphs with small degree. Finally, we further investigate the relationship between splits in bitonic st-orderings and bends in upward planar polyline drawings with polynomial area, by providing bounds on the number of bends in such drawings.
... Let G be a biconnected graph. An SPQR-tree T of G is a tree-like data structure that represents the decomposition of G into its triconnected components, which can be computed in linear time [43,65,71]. See Fig. 11 for an illustration. ...
Article
Full-text available
A k-page upward book embedding (kUBE) of a directed acyclic graph G is a book embeddings of G on k pages with the additional requirement that the vertices appear in a topological ordering along the spine of the book. The k UBE Testing problem, which asks whether a graph admits a kUBE, was introduced in 1999 by Heath, Pemmaraju, and Trenk (SIAM J Comput 28(4), 1999). In a companion paper, Heath and Pemmaraju (SIAM J Comput 28(5), 1999) proved that the problem is linear-time solvable for $$k=1$$ and NP-complete for $$k = 6$$. Closing this gap has been a central question in algorithmic graph theory since then. In this paper, we make a major contribution towards a definitive answer to the above question by showing that k UBE Testing is NP-complete for $$k\ge 3$$, even for st-graphs, i.e., acyclic directed graphs with a single source and a single sink. Indeed, our result, together with a recent work of Bekos et al. (Theor Comput Sci 946, 2023) that proves the NP-completeness of 2UBE for planar st-graphs, closes the question about the complexity of the kUBE problem for any k. Motivated by this hardness result, we then focus on the 2UBE Testing for planar st-graphs. On the algorithmic side, we present an $$O(f(\beta )\cdot n+n^3)$$-time algorithm for 2UBE Testing, where $$\beta$$ is the branchwidth of the input graph and f is a singly-exponential function on $$\beta$$. Since the treewidth and the branchwidth of a graph are within a constant factor from each other, this result immediately yields an FPT algorithm for st-graphs of bounded treewidth. Furthermore, we describe an O(n)-time algorithm to test whether a plane st-graph whose faces have a special structure admits a 2UBE that additionally preserves the plane embedding of the input st-graph. On the combinatorial side, we present two notable families of plane st-graphs that always admit an embedding-preserving $$2$$UBE.
... Because triconnected component decomposition can be regarded as a tree decomposition, we extend our query algorithms for graphs represented by using the tree decomposition. Though computing the exact treewidth is NP-hard, whereas triconnected component decomposition is done in linear time [8], and query time complexities using tree decomposition is larger than using triconnected component decomposition, the treewidth is always at most r and therefore algorithms based on the tree decomposition are faster in some cases. In view of these, we remake the indexing data structures and algorithms for tree decomposition. ...
Preprint
Given a directed edge-weighted graph $G=(V, E)$ with beer vertices $B\subseteq V$, a beer path between two vertices $u$ and $v$ is a path between $u$ and $v$ that visits at least one beer vertex in $B$, and the beer distance between two vertices is the shortest length of beer paths. We consider \emph{indexing problems} on beer paths, that is, a graph is given a priori, and we construct some data structures (called indexes) for the graph. Then later, we are given two vertices, and we find the beer distance or beer path between them using the data structure. For such a scheme, efficient algorithms using indexes for the beer distance and beer path queries have been proposed for outerplanar graphs and interval graphs. For example, Bacic et al. (2021) present indexes with size $O(n)$ for outerplanar graphs and an algorithm using them that answers the beer distance between given two vertices in $O(\alpha(n))$ time, where $\alpha(\cdot)$ is the inverse Ackermann function; the performance is shown to be optimal. This paper proposes indexing data structures and algorithms for beer path queries on general graphs based on two types of graph decomposition: the tree decomposition and the triconnected component decomposition. We propose indexes with size $O(m+nr^2)$ based on the triconnected component decomposition, where $r$ is the size of the largest triconnected component. For a given query $u,v\in V$, our algorithm using the indexes can output the beer distance in query time $O(\alpha(m))$. In particular, our indexing data structures and algorithms achieve the optimal performance (the space and the query time) for series-parallel graphs, which is a wider class of outerplanar graphs.
Article
We introduce the problem Syn chro nized Pla nari ty . Roughly speaking, its input is a loop-free multi-graph together with synchronization constraints that, e.g., match pairs of vertices of equal degree by providing a bijection between their edges. Syn chro nized Pla nari ty then asks whether the graph admits a crossing-free embedding into the plane such that the orders of edges around synchronized vertices are consistent. We show, on the one hand, that Syn chro nized Pla nari ty can be solved in quadratic time, and, on the other hand, that it serves as a powerful modeling language that lets us easily formulate several constrained planarity problems as instances of Syn chro nized Pla nari ty . In particular, this lets us solve Clus tered Pla nari ty in quadratic time, where the most efficient previously known algorithm has an upper bound of O ( n ⁸ ).
Chapter
Given a mixed graph G, we consider the problem of computing the maximal sets of vertices $$C_1,C_2,\ldots ,C_k$$ with the property that by removing any edge e from G, there is an orientation $$R_i$$ of $$G\setminus {e}$$ such that all vertices in $$C_i$$ are strongly connected in $$R_i$$. We study properties of those sets, and show how to compute them in linear time via a reduction to the computation of the 2-edge twinless strongly connected components of a directed graph. A directed graph G is twinless strongly connected if it contains a strongly connected spanning subgraph without any pair of antiparallel (or twin) edges. The twinless strongly connected components (TSCCs) of G are its maximal twinless strongly connected subgraphs. A 2-edge twinless strongly connected component (2eTSCC) of G is a maximal subset of vertices C such that any two vertices $$u, v \in C$$ are in the same twinless strongly connected component TSCC of $$G \setminus e$$, for any edge e. These concepts are motivated by several diverse applications, such as the design of road and telecommunication networks, and the structural stability of buildings.KeywordsConnectivityOrientationsMixed Graphs
Chapter
In this paper, we present the first linear delay algorithms to enumerate all 2-edge-connected induced subgraphs and to enumerate all 2-vertex-connected induced subgraphs for a given simple undirected graph. We treat these subgraph enumeration problems in a more general framework based on set systems. For an element set V, $$(V,{\mathcal C}\subseteq 2^V)$$ is called a set system, where we call $$C\in {\mathcal C}$$ a component. A nonempty subset $$Y\subseteq C$$ is a removable set of C if $$C\setminus Y$$ is a component and Y is a minimal removable set (MRS) of C if it is a removable set and no proper nonempty subset $$Z\subsetneq Y$$ is a removable set of C. We say that a set system has subset-disjoint (SD) property if, for every two components $$C,C'\in {\mathcal C}$$ with $$C'\subsetneq C$$, every MRS Y of C satisfies either $$Y\subseteq C'$$ or $$Y\cap C'=\emptyset$$. We assume that a set system with SD property is implicitly given by an oracle that returns an MRS of a component which is given as a query. We provide an algorithm that, given a component C, enumerates all components that are subsets of C in linear time/space with respect to |V| and oracle running time/space. We then show that, given a simple undirected graph G, the pair of the vertex set $$V=V(G)$$ and the family of vertex subsets that induce 2-edge-connected (or 2-vertex-connected) subgraphs of G has SD property, where an MRS in a 2-edge-connected (or 2-vertex-connected) induced subgraph corresponds to either an ear or a single vertex with degree greater than two.KeywordsEnumeration of subgraphs2-edge-connectivity2-vertex-connectivityBinary partitionLinear delay
Article
Partitioning the Maximal Redundant Rigid Components (MRRC) and Maximal Global Rigid Components (MGRC) in generic 2D graphs are critical problem for network structure analysis, network localizability detection, and localization algorithm design. This paper presents efficient algorithms to partition MRRCs and MGRCs and develops an open-sourced toolbox, GPART, for these algorithms to be conveniently used by the society. We firstly propose conditions and an efficient algorithm to merge the over-constrained regions to form the maximal redundant rigid components (MRRC). The detected MRRCs are proved to be maximal and all the MRRCs are guaranteed to be detected. The time to merge the over-constrained regions is linear to the number of nodes in the over-constrained components. To detect MGRCs, the critical problem is to decompose 3-connected components in each MRRC. We exploit SPQR-tree based method and design a local optimization algorithm, called MGRC_acce to prune the unnecessary decomposition operations so that the SPQR-tree functions can be called much less number of times. We prove the MGRCs can be detected inside MRRCs using at most O ( mn ) time. Then a GPART toolbox is developed and extensively tested in graphs of different densities. We show the proposed MRRC and MGRC detection algorithms are valid and MGRC_acce greatly outperforms the direct SPQR-tree based decomposition algorithm. GPART is outsourced at https://github.com/inlab-group/gpart.
Article
Full-text available
Computing a crossing minimum drawing of a given planar graph G augmented by an additional edge e where all crossings involve e, has been a long standing open problem in graph drawing. Alternatively, the problem can be stated as finding a combinatorial embedding of a planar graph G where the given edge e can be inserted with the minimum number of crossings. Many problems concerned with the optimization over the set of all combinatorial embeddings of a planar graph turned out to be NP-hard. Surprisingly, we found a conceptually simple linear time algorithm based on SPQR-trees, that is able to find a solution with the minimum number of crossings.
Conference Paper
Full-text available
Computing a crossing minimum drawing of a given planar graph G augmented by an additional edge e in which all crossings involve e, has been a long standing open problem in graph drawing. Alternatively, the problem can be stated as finding a planar combinatorial embedding of a planar graph G in which the given edge e can be inserted with the minimum number of crossings. Many problems concerned with the optimization over the set of all combinatorial embeddings of a planar graph turned out to be NP-hard. Surprisingly, we found a conceptually simple linear time algorithm based on SPQR trees, which is able to find a crossing minimum solution.
Book
Full-text available
The lack of standard library of the data structures and algorithms of combinatorial and geometric computing severely limits the impact of this area on computer science. To address this problem, the LEDA project was introduced in 1989 to build a library of the data types and algorithms of combinatorial and geometric computing. Among its many features, LEDA provides a sizable collection of data types and algorithms in a form that allows them to be used by non-experts. Sample applications are code optimization, motion planning, logic synthesis, scheduling, VLSI design, term rewriting systems, semantic nets, machine learning, image analysis, computational biology, etc.
Article
We consider the problem of maintaining on-line the triconnected components of a graphG. Letn be the current number of vertices ofG. We present anO(n)-space data structure that supports insertions of vertices and edges, and queries of the type Are there three vertex-disjoint paths between verticesv 1 andv 2? A sequence ofk operations takes timeO(k(k, n)) ifG is biconnected((k, n) denotes the well-known Ackermann's function inverse), and timeO(n logn+k) ifG is not biconnected. Note that the bounds do not depend on the number of edges ofG. We use theSPQR-tree, a versatile data structure that represents the decomposition of a biconnected graph with respect to its triconnected components, and theBC-tree, which represents the decomposition of a connected graph with respect to its biconnected components.
Article
We introduce a new method to optimize the required area, minimum angle, and number of bends of planar graph drawings on a grid. The main tool is a new type of ordering on the vertices and faces of triconnected planar graphs. Using this method linear-time-and-space algorithms can be designed for many graph-drawing problems. Our main results are as follows: Every triconnected planar graphG admits a planar convex grid drawing with straight lines on a (2n–4)(n–2) grid, wheren is the number of vertices.  Every triconnected planar graph with maximum degree 4 admits a planar orthogonal grid drawing on annn grid with at most [3n/2]+4 bends, and ifn>6, then every edge has at most two bends.  Every planar graph with maximum degree 3 admits a planar orthogonal grid drawing with at most [n/2]+1 bends on an [n/2][n/2] grid.  Every triconnected planar graphG admits a planar polyline grid drawing on a (2n–6)(3n–9) grid with minimum angle larger than 2/d radians and at most 5n–15 bends, withd the maximum degree. These results give in some cases considerable improvements over previous results, and give new bounds in other cases. Several other results, e.g., concerning visibility representations, are included.
Article
We present polynomial-time algorithms for computing an embedding of a planar graph that minimizes the outerplanarity, or the width, or the radius, or some other measures of distance to the outer face. On the other hand, we show it is NP-hard to compute an embedding that minimizes the diameter of the dual graph.
Conference Paper
We present the SPQR-tree, a versatile data structure that represents the decomposition of a biconnected graph with respect to its triconnected components, and show its application to a variety of on-line graph algorithms dealing with triconnectivity, transitive closure, minimum spanning tree, and planarity testing. The results are further extended to general graphs by means of another data structure, the BC-tree.
Article
The on-line planarity-testing problem consists of performing the following operations on a planar graph G: (i) testing if a new edge can be added to G so that the resulting graph is itself planar; (ii) adding vertices and edges such that planarity is preserved. An efficient technique for on- line planarity testing of a graph is presented that uses O(n) space and supports tests and insertions of vertices and edges in O(log n) time, where n is the current number of vertices of G. The bounds for tests and vertex insertions are worst-case and the bound for edge insertions is amortized. We also present other applications of this technique to dynamic algorithms for planar graphs.