The symmetry number problem for trees
Kien-Weh Chin, Hsu-Chun Yen
∗Department of Electrical Engineering, National Taiwan University, Taipei, Taiwan
Received 4 July 2000 Communicated by T. Lengauer
Abstract
For trees, we define the notion of the so-called symmetry number to measure the size of the maximum subtree that exhibits an axial symmetry in graph drawing. For unrooted unordered trees, we are able to demonstrate a polynomial time algorithm for computing the symmetry number.2001 Elsevier Science B.V. All rights reserved.
Keywords: Design of algorithms; Graph drawing
1. Introduction
Graphs are known to be useful for modeling vari-ous scientific/engineering problems in the real world. Because of the popularity of graphs, graph drawing has emerged as a research topic of great importance in graph theory. In many cases, a ‘pretty drawing’ of-ten offers more insights into the nature of a graph. A natural question arises: How to define ‘pretty draw-ings?’ Aesthetic guidelines suggested in the literature (see, e.g., [1,8]) for drawing pretty graphs include min-imizing the number of edge crossings, minmin-imizing the variance of edge lengths, minimizing the number of bends, as well as drawing edges orthogonally or using straight-line segments. Such criteria are by no means comprehensive in spite of the fact that they are widely recognized as the most frequently used guidelines in graph drawing in general. From the viewpoint of com-putational complexity, many of the graph drawing re-lated problems are intractable.
*Corresponding author.
E-mail address: yen@cc.ee.ntu.edu.tw (H.-C. Yen).
Recently, another aesthetic criterion, namely
sym-metry, has received increasing attention in the graph
drawing community [2,4,6,7]. In particular, in [2] sev-eral types of symmetries (including reflectional and
rotational symmetries) have been characterized in a
unified way using geometric automorphism groups. As a symmetric graph can be ‘decomposed’ into a number of isomorphic subgraphs, only a portion of the graph, together with the symmetric information, is sufficient to define the original graph. In this way, symmetric graphs can often be represented in a more succinct fashion than their asymmetric counterparts. Moreover, to draw a graph nicely, a good starting point might be to draw its symmetric subgraph as large as possible first, and then add the remaining nodes and edges to the drawing. Unfortunately, like many of the graph drawing problems, deciding whether a graph has an axial (reflectional) or rotational symmetry is com-putationally intractable [7].
In this paper, we define a new quantitative measure of symmetry (called symmetry number) for trees. More precisely, the symmetry number of a tree is the size (number of nodes) of the maximum subtree which
0020-0190/01/$ – see front matter 2001 Elsevier Science B.V. All rights reserved. PII: S 0 0 2 0 - 0 1 9 0 ( 0 0 ) 0 0 1 7 4 - 5
than or equal to k. For unrooted unordered trees, we are able to come up with a polynomial time algorithm to solve the symmetry number problem.
2. Graphs, graph drawing and symmetry
An unordered unrooted tree is a connected, undi-rected, and acyclic graph without a specific root. A subtree of an unordered unrooted tree G is sim-ply a connected subgraph of G. The main concern in this research is to decide, given an unordered unrooted tree G, G’s maximum subtree that exhibits an axial
symmetric in the fashion of straight-line upward
draw-ing [1].
A drawing of a graph G on the plane is a mapping
D from the nodes of G to R2, whereR is the set of real numbers. That is, each node v is placed at point
D(v) on the plane, and each edge (u, v) is displayed
refer to trees whose top level (either a node or an edge) is fixed, and the top level is called the root. A rooted tree is said to have an axial symmetry if we can draw the tree (in the fashion of upward drawing) together with a straight line (called the symmetry axis) such that each node (and edge) is either on the symmetry axis or has a unique corresponding image on the opposite side of the axis. (That is, the drawing is symmetric with respect to the axis.) Unless stated otherwise, we simply use ‘symmetry’ to denote ‘axial symmetry’ and trees are assumed to be unordered throughout the rest of this paper. (The reader is referred to [2,7] for more about symmetry in graph drawing and other types of symmetries such as rotational symmetry.)
Given a rooted tree T and a vertex v, we write Tv
to denote the rooted tree (with root v) whose vertices
are all descendants of v, and Cvto represent the set of
v’s children (Cv= ∅ if v is a leaf node). Tvis called a subtree of T . An r-subtree of T is a rooted tree
Fig. 2. Subtree and r -subtree of a rooted tree.
generated from T by cutting off some of T ’s subtrees. (See Fig. 2 for an example of an r-subtree by cutting
off subtrees T1 and T2.) Notice that T and any of its
nonempty r-subtrees share the same root.
The symmetry number of an unrooted tree G is defined to be the maximum number of nodes among
G’s subtrees that have an axial symmetry. (Recall that
a subtree of an unrooted tree is simply a connected subgraph.) The symmetry number problem is the problem of, given an unordered unrooted tree G and an integer k, determining whether the symmetry number of G is greater than or equal to k.
Even though in this paper we mainly focus on trees, we feel that the notion of ‘drawing the maximum symmetric subgraph’ of a general graph is likely to play an interesting role in graph drawing. To draw a graph nicely, a good starting point might be to draw its symmetric subgraph as large as possible first, and then add the remaining nodes and edges to the drawing. Following a result in [7], for general graphs the symmetry number problem is NP-complete.
3. Deciding the symmetry number for trees
In this section, we design a polynomial time algo-rithm to calculate the symmetry number for unrooted unordered trees. Our algorithm utilizes the solution of the weighted matching problem which is defined as follows.
A matching M on a graph G= (V, E) is a subset
of E (i.e., M⊆ E) such that any two edges in M have
no common vertex. The weighted matching problem
Fig. 3. An instance of the weighted matching problem.
is that of given a graph G= (V, E) with a weight
function w : E→ N, finding a matching M such that
e∈Mw(e) is maximum. Take Fig. 3 for example. It is reasonably easy to see that edges (A, F), (B, E) and (C, D) constitute a maximum matching whose total weight is 42. It is known that the weighted matching
problem for graphs is solvable in O(n3) time, where
n is the number of nodes (see [5]). For n-node
m-edge bipartite graphs with integral m-edge weights, the
problem can be solved in O(√n∗ m ∗ log(nW)) time,
where W is the maximum weight (see [3]).
We are now in a position to describe our algorithm for finding the symmetry number for unrooted trees. It should be noted that our algorithm is not responsible for doing the actual drawing of the maximum sym-metric subtree, although displaying such a symsym-metric drawing is interesting and deserves further investiga-tion.
Theorem 3.1. The symmetry number problem for unrooted unordered trees is solvable in polynomial time.
Proof. First consider an n-node rooted tree T = (V , E), and without loss of generality, we let V =
{v1, v2, . . . , vn}. We define two functions A(vi) and
B(vi, vj), where vi, vj ∈ V , as follows.
• Function A(vi) returns the number of nodes in the
maximum symmetric r-subtree of Tvisubject to the
constraint that vi being on the symmetry axis. (For
the rooted tree displayed in Fig. 4(a), A(3)= 5. See
Fig. 4(b).)
• Function B(vi, vj) returns the number of nodes in
the maximum r-subtree of Tvi that is isomorphic to
an r-subtree of Tvj. In words, B(vi, vj) is the size
of the maximum common r-subtree of Tvi and Tvj.
(Notice that B(vi, vj)= B(vi, vj).) As Fig. 4(c)
Fig. 4. The use of maximum weighted matching to find the maximum symmetric r -subtree.
(Intuitively, B(vi, vj) is to capture the following
idea: should vi be mapped to vj in a symmetric
drawing, B(vi, vj) is the maximum amount that
each of vi and vj (with their r-subtrees) can
contribute to the symmetric drawing.)
A(vi) and B(vi, vj) are computed recursively by
proceduresA(vi) andB(vi, vj) as follows.
ProcedureA(vi)
if viis a leaf node thenA(vi)= 1
else
construct a weighted complete graph Gvi= (V, E)
with weight function w, such that
V= {vi} ∪ Cvi (Cvi= the set of vi’s children)
w(vi, vl)= A(vl), ∀vl∈ Cvi
w(vp, vq)= 2B(vp, vq), ∀vp, vq∈ Cvi
return 1+ (weight of maximum matching of Gvi)
ProcedureB(vi, vj)
if vi or vj is a leaf node thenB(vi, vj)= 1
else
construct a weighted complete bipartite graph Gvi,vj= (Vi∪ Vj, E)
with weight function w, such that
Vi= Cvi and Vj= Cvj
w(vp, vq)= B(vp, vq),∀vp∈ Vi, vq∈ Vj
(a) (b) Fig. 5. Symmetric drawing vs. maximum matching.
To give the reader a better feeling for the above argument, consider the tree T (with root 1) depicted in Fig. 4(a). Clearly, the size of the maximum symmetric
r-subtree rooted at node 2 is 4; A(2) is 4. B(2, 3)= 4
since the size of the maximum isomorphic r-subtrees rooted at nodes 2 and 3 is 4. Similarly, it is easy
to see that A(3)= 5, A(4) = 3, B(2, 4) = 3, and
B(3, 4)= 4. Fig. 4(d) displays the complete graph G1
during the computation of A(1) with respect to the tree in Fig. 4(a). The maximum weighted matching
with respect to G1contains the edges (1, 2) and (3, 4)
with total weight 12. Thus, the number of nodes in the maximum symmetric r-subtree of T is 13. A drawing of the corresponding maximum symmetric r-subtree of T is shown in Fig. 4(e). (The display is merely for the illustrating purpose; our algorithm does not produce such a drawing.) Notice that node 2 is on the symmetry axis, for edge (1, 2) is included in the
maximum matching of G1.
We now prove the correctness of proceduresA(vi)
andB(vi, vj). First consider procedureB(vi, vj). The
proof of the correctness of procedure B(vi, vj) (i.e.,
showing B(vi, vj)= B(vi, vj)) is done by induction
on the height k in the shorter of Tvi and Tvj. (Recall
that the height of a rooted tree is the length of a longest
path from the root to a leaf.) The case k= 0 is trivial.
Assuming that the assertion holds for 0 k l, we
consider k= l + 1. To prove B(vi, vj)= B(vi, vj), we
proceed by showing both B(vi, vj) B(vi, vj) and
B(vi, vj) B(vi, vj). Let f be a mapping (between
r-subtrees of Tvi and Tvj) which witnesses B(vi, vj).
Notice that f (vi)= vj and suppose f (vir)= vjr
(∀r, 1 r m, for some m), where {vi1, . . . , vim} ⊆ Cvi and {vj1, . . . , vjm} ⊆ Cvj. See Fig. 5(a). Then according to the induction hypothesis,
∀r, 1 r m, B(vir, vjr)= B(vir, vjr). Hence, B(vi, vj)= 1 + m r=1 B(vir, vjr)= 1 + m r=1 B(vir, vjr), which is less than or equal to one plus the maximum
matching of Gvi,vj (because
m
r=1{(vir, vjr)} forms
a matching on Gvi,vj). Hence, B(vi, vj) B(vi, vj).
Conversely, suppose mr=1 {(vir, vjr)} (for some m)
is a matching on graph Gvi,vj. Since for every r, vir
(respectively, vjr) is a child of vi (respectively, vj),
by the induction hypothesisB(vir, vjr)= B(vir, vjr).
A common r-subtree between Tvi and Tvj can be
found by mapping vi to vj, and the r-subtrees of Tv
ir and Tvj r witnessingB(vir, vjr) to each other, 1 r
m. By doing so, we immediately have thatB(vi, vj)
B(vi, vj). In view of the above, we conclude that
B(vi, vj)= B(vi, vj), which completes the proof of
the induction step for procedureB(vi, vj).
The proof of the correctness of procedure A(vi)
cases:
(1) vi is involved in M. That is,
M=(vi, vl) ∪ m r=1 {(vir, vjr)} ,
for some l and m. By the induction hypothesis, a
symmetric r-subtree of Tvl withA(vl) nodes can
be found. By placing the isomorphic r-subtrees
(of sizeB(vir, vjr), guaranteed by the correctness
of procedureB) of Tv
ir and Tvj r (1 r m
) on
the two sides of the symmetry axis, a symmetric
drawing of 1+ A(vl)+
m
i=12B(vir, vjr) nodes can be found. See Fig. 5(b).
(2) vi is not involved in M. That is,
M= m r=1 (vir, vjr) ,
for some m. By placing the isomorphic r-subtrees
(of sizeB(vir, vjr), guaranteed by the correctness
of procedureB) of Tvir and Tvj r (1 r m) on
the two sides of the symmetry axis, a symmetric drawing of 1+mr=1 2B(vir, vjr) nodes can be found.
Either (1) or (2) above indicates that an r-subtree
of T (vi) with at least A(vi) nodes can be drawn
symmetrically. Hence,A(vi) A(vi).
Conversely, consider an r-subtree D of Tvi that
exhibits a symmetric drawing. Depending on whether
a node in Cvilies on the symmetry axis or not, we have
the following two cases:
(i) A vl is on the axis. In this case, the size of Tvl’s
symmetric r-subtree in D is bounded by A(vl)
(= A(vl), by the induction hypothesis). (Recall
that A(vl) defines the maximum size of symmetric
r-subtrees of Tvl.) This, in conjunction with the
correctness of procedureB, suggests that the size
of D is bounded by 1+ A(vl)+ m r=1 2B(vir, vjr), 1+ r=1 2B(vir, vjr),
where{vi1, . . . , vim, vj1, . . . , vjm} is the set of vi’s children participated in D, and the corresponding
image of vir in the symmetric drawing is vjr.
By the definition of procedure A, we immediately
have that the size of D is bounded by the maximum
matching on Gvi. Hence, A(vi) A(vi).
For rooted tree T of n nodes, let time(A(vi)) and
time(B(vi, vj)) be the times needed for procedures
A(vi) andB(vi, vj), respectively. Let ni= |Cvi| and
nj = |Cvj|, i.e., the numbers of children of vi and
vj, respectively. It is easy to observe that for each
pair of nodes vi and vj, B(vi, vj) is computed at
most once, since there is exactly one path from the
root to any node in T . In procedure B(vi, vj), the
time needed to construct the bipartite graph Gvi,vj
(which has O(ni∗nj) edges) is bounded by O(ni∗nj),
given that∀vp∈ Cvi,∀vq∈ Cvj,B(vp, vq) are already
computed. Recall that for n-node m-edge bipartite graphs with integral edge weights, the maximum
matching problem can be solved in O(√n∗ m ∗
log(nW )) time, where W is the maximum weight [3].
The complexity of computingB(vi, vj) is therefore
bounded by O ninj+ ni+ njninjlog((ni+ nj)∗ n) = O ninj(1+ ni+ nj) log n O ninj √ n log n. Hence, vi,vj∈V time B(vi, vj) = n i=1 n j=1 O ninj √ n log n O n i=1 ni n j=1 nj √ n log n = O n∗ n ∗√n log n= O n2.5log n.
Once all theB(vi, vj), 1 i, j n, are calculated,
computing A(vi) requires first building a weighted
graph Gvi of ni + 1 nodes and then solving the
weighted maximum matching problem for Gvi. The
former is doable in O((ni+ 1)2) time, and the latter
can be done in O((ni+ 1)3) [5]. Hence,
vi∈V time(A(vi)) = n i=1 O((ni+ 1)2)+ O((ni+ 1)3) = n i=1 O (ni)3 O n i=1 ni 3 = O n3 time.
The above derivation is under the assumption that the root of a tree is given. Now for an unrooted tree
G(= (V, E)), the symmetry number equals
maxmax
vi∈V{A(vi)}, max(vi,vj)∈E{B(vi, vj)}
,
whose computation time amounts to O(n4)+
O(n3.5log n)= O(n4). (The first (respectively,
sec-ond) term corresponds to the case when the top level
of the maximum symmetric subtree is node vi
(re-spectively, edge (vi, vj)). Also notice that Tvi and
Tvj depend on the root of tree T ; hence,A(vi) and
B(vi, vj) have to be re-computed when the root of the tree changes.) This completes the proof of the
theo-rem. ✷
Acknowledgements
The authors thank the anonymous referees for comments which improved the presentation as well as the correctness of the paper.
References
[1] G. Battista, P. Eades, R. Tamassia, I. Tollis, Graph Drawing: Algorithms for the Visualization of Graphs, Prentice-Hall, Englewood Cliffs, NJ, 1999.
[2] P. Eades, X. Lin, Spring algorithms and symmetry, in: Comput-ing and Combinatorics (COCOON’97), Lecture Notes in Com-put. Sci., Vol. 1276, Springer, Berlin, 1997, pp. 202–211. [3] H. Gabow, R. Tarjan, Faster scaling algorithms for network
problems, SIAM J. Comput. 18 (5) (1989) 1013–1036. [4] S. Hong, P. Eades, A. Quigley, S. Lee, Drawing algorithms
for series-parallel digraphs in two and three dimensions, in: Graph Drawing’98, Lecture Notes in Comput. Sci., Vol. 1547, Springer, Berlin, 1998, pp. 198–209.
[5] E. Lawer, Combinatorial Optimization: Networks and Matroids, Holt, Rinehart & Winston, New York, 1976.
[6] J. Manning, M. Atallah, Fast detection and display of symmetry in trees, Congr. Numer. 64 (1988) 159–169.
[7] J. Manning, Geometric symmetry in graphs, Ph.D. Dissertation, Dept. of Computer Science, Purdue University, West Lafayette, IN, 1990.
[8] R. Tamassia, Graph drawing, in: J.E. Goodman, J. O’Rourke (Eds.), CRC Handbook of Discrete and Computational Geome-try, CRC Press, Rockville, MD, 1997.