Content uploaded by Carsten Gutwenger
Author content
All content in this area was uploaded by Carsten Gutwenger
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
2Technische Universit¨at Wien, Austria, mutzel@ads.tuwien.ac.at
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 field of graph algorithms.
Theoretical papers using SPQR-trees claim that they can be implemen-
ted 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 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 field
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 specific 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 finding 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 “Effiziente
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 v→w. If there is a (directed) path from vto w, we write v∗
→w.
If v→w,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 v→w) 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 identifies 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=(V1∪V2,(E1∪E2)\{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 defined in [8] for planar graphs only. Here, we cite the more
general definition 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 defined 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
k−1(k≥2) 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=(ci−1,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}(k≥1), 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 Gi∪eiwith 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 different, but equivalent, definition
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 definition 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 modified definition, 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 definition 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 off one Gi,
1≤i≤and 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 final 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 suffices 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 modified 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 first 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 off 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 finds 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 e∈Cido
2.2 if there exists j6=iwith e∈Cjand type(Ci)=type(Cj)then
2.3 Ci:= (Ci∪Cj)\{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 v∈Vand 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=v→w,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 ≤i≤i0,
and lowpt2(wj)≥vfor i0<j≤n.Ifv→u∈E0, then v→ucomes in
Adj (v) between v→wi0and v→wi0+1.
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 v→wi0and v→wi0+1 in Adj (v). This
can easily be done by adapting the sorting function φused in [15]:
φ(e)=
3lowpt1(w)ife=v→wand lowpt2(w)<v
3w+1 ife=v→w
3lowpt1(w)+2if e=v→wand 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-first-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 first path starts at vertex 1 and a
path ends, when the first 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 satisfies (P1)-(P3).
The edges are numbered according to the generated paths. The generated paths
are
1: 1 →2→3→13 →17:12→9
2: 13 →28:10→11 →8
3: 3 →4→19:11→9
4: 4 →5→8→1 10: 5 →6→7→4
5: 8 →9→10 →12 →1 11: 7 →5
6: 12 →8 12: 6 →4
We need one more definition: unis a first descendant of u0if u0→··· → un
and each ui→ui+1 is the first 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 b→r,
lowpt1(r)=a, lowpt2(r)≥b, and sis not a descendant of r.
Type-2 Case: There is a vertex r6=bsuch that a→r∗
→b,bis a first descendant
of r,a6=1, every frond x→ywith r≤x<bhas a≤y, and every frond
x→ywith a<y<band b→w∗
→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 v→wa 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 off, 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
added to component Cand Gc.
make tree edge(e, v →w): makes edge e=(v, w) a new tree edge in Pc.
Moreover, we define the access functions
firstChild(v) = first child of vin Pcaccording to Adj (v).
high(w)=0ifF(w)=∅
source vertex of first visited edge in F(w) otherwise
where F(w)={v|v→w∈Ec}, and we use two stacks for which the usual
functions push,pop, and top are defined:
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 off.
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 find 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)
forall e∈Adj(v)do
if e=v→wthen
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(v→w)
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
firstChild(w)>w)) do
if a=vand parent(b)=athen
TSTACK.pop()
else
eab := nil
if deg(w)=2and firstChild(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 a≤x≤hand a≤y≤hdo
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 w≤x<w+ND (w)or w≤y<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 v∈Gc. It is updated each time
an edge is added to or removed from Gc.
–In order to compute firstChild(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 vi→wending
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 iff 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 modified 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 modified.
–The updates for firstChild (v) (which is A1(v) in [15]) and DEGREE(v) were
not sufficient.
–high(w) (which is HIGHPT(w) in [15]) was not updated, which is not correct.
It is necessary to update HIGHPT dynamically, when Gcis modified. 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 m−nsplit 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 configuration: Pentium II, 400 MHz, 128MB
RAM)
References
[1] AGD User Manual (Version 1.1.2), Feb. 2000. Max-Planck-Institut Saarbr¨ucken,
Technische Universit¨at Wien, Universit¨at zu K¨oln, Universit¨at Trier. See also
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, Universit`a 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. Efficient 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.