Next Article in Journal
Convolutional Neural Network Approach for Multispectral Facial Presentation Attack Detection in Automated Border Control Systems
Previous Article in Journal
Sequentially Estimating the Approximate Conditional Mean Using Extreme Learning Machines
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Enumerating Tree-Like Graphs and Polymer Topologies with a Given Cycle Rank

by
Naveed Ahmed Azam
*,
Aleksandar Shurbevski
and
Hiroshi Nagamochi
Department of Applied Mathematics and Physics, Kyoto University, Kyoto 606-850, Japan
*
Author to whom correspondence should be addressed.
Entropy 2020, 22(11), 1295; https://doi.org/10.3390/e22111295
Submission received: 26 October 2020 / Revised: 4 November 2020 / Accepted: 9 November 2020 / Published: 13 November 2020

Abstract

:
Cycle rank is an important notion that is widely used to classify, understand, and discover new chemical compounds. We propose a method to enumerate all non-isomorphic tree-like graphs of a given cycle rank with self-loops and no multiple edges. To achieve this, we develop an algorithm to enumerate all non-isomorphic rooted graphs with the required constraints. The idea of our method is to define a canonical representation of rooted graphs and enumerate all non-isomorphic graphs by generating the canonical representation of rooted graphs. An important feature of our method is that for an integer n 1 , it generates all required graphs with n vertices in O ( n ) time per graph and O ( n ) space in total, without generating invalid intermediate structures. We performed some experiments to enumerate graphs with a given cycle rank from which it is evident that our method is efficient. As an application of our method, we can generate tree-like polymer topologies of a given cycle rank with self-loops and no multiple edges.

1. Introduction

The problem of enumerating discrete structures has several applications in applied fields such as graph theory, chemoinformatics, bioinformatics, and material informatics [1,2,3,4,5,6,7,8,9,10,11]. In particular, the enumeration of chemical compounds is widely used in the discovery of novel drugs [12,13,14,15,16,17] and structural elucidation [18]. It is necessary for an enumeration method to generate all possible required structures without duplication in low computational complexity, due to which designing an enumeration method is not an easy task.
The problem of the enumeration of chemical compounds with given constraints is often modeled as the problem of the enumeration of graphs. Several chemical compound generation methods have been proposed [3,4,5,6,7,8,9], where some methods [3,4] focus on general chemical compounds, while the other methods [5,6,7,8] deal with restricted chemical graphs. These methods are mainly based on the branching algorithm paradigm; the required chemical compounds appear at the leaves of a computation tree. However, these algorithms generate many invalid intermediate structures that appear at the non-leaf nodes of the computation tree [9]. Due to this fact, these methods are inefficient to generate chemical compounds with more than 20 non-hydrogen atoms. Thus, it is natural to explore and develop such methods that can enumerate chemical compounds without generating invalid intermediate structures. Jin et al. [9] proposed one such chemical compound generation method based on the junction tree and the variational autoencoder.
For a chemical compound C, the polymer topology is a connected multi-graph where all vertices have degree at least three obtained by iteratively removing all vertices of degree at most two from C [19]. For example, the polymer topologies of the chemical compounds remdesivir C 27 H 35 N 6 O 8 P (Figure 1a) and dexamethasone C 22 H 29 FO 5  (Figure 1b) are illustrated in Figure 1c,d, respectively. Observe that two different chemical compounds can have the same polymer topology, and the categorization of polymer topologies can play an important role in understanding and studying the synthetic pathways of macro-chemical compounds [20]. Polymer topologies P are often classified with respect to their cycle rank, which is the number of edges that are necessary to remove to get a spanning tree of P. Haruna et al. [19] developed an enumeration method to generate all polymer topologies with a given rank by using frontier-based search and zero-suppressed decision diagrams. As a result, they enumerated all polymer topologies with cycle rank at most 6. For a multi-graph G, we define the skeleton to be the simple graph obtained by removing all self-loops and multiple edges from G. Notice that the class of graphs with a tree skeleton, Δ 0 self-loops, and no multiple edges contains all tree-like polymer topologies with cycle rank Δ , and therefore, it is an interesting problem to enumerate all such graphs. Figure 2 illustrates examples of chemical compounds that have tree-like polymer topologies with self-loops and no multiple edges. Recently, Azam et al. [21] proposed a method to count all trees with given numbers of vertices and self-loops by using dynamic programming. As a result, they gave the upper bound and the lower bound on the number of tree-like mutually non-isomorphic polymer topologies with a given rank.
This article aims to develop an efficient method to enumerate all mutually non-isomorphic graphs with a tree skeleton, n vertices, Δ self-loops, and no multiple edges without generating invalid intermediate structures. The idea of our method is to define a canonical representation of rooted graphs with the said structures and then enumerate these graphs by generating their canonical representations. As a consequence of our method, we can get all polymer topologies with a tree skeleton, a given cycle rank, self-loops, and no multiple edges. We organize the paper as follows: In Section 2, we discuss some preliminaries. In Section 3, we first prove the mathematical properties based on which we develop our enumeration method. We discuss experimental results and an application of our enumeration method to generate all polymer topologies with a tree skeleton and a given cycle rank in Section 4. We conclude and discuss some future directions in Section 5.

2. Preliminaries

For a graph G, let V ( G ) denote the vertex set and  E ( G ) denote the edge set. Let n ( G ) denote | V ( G ) | and self ( G ) denote the number of self-loops in G. We define size s ( G ) of graph G to be the sequence ( n ( G ) , self ( G ) ) . Let s ( v ) denote the number of self-loops on v V ( G ) . For v V ( G ) , we denote by N G ( v ) the set of neighbors of v other than v. The degree deg G ( v ) of v V ( G ) is defined to be the size of N G ( v ) .
For a multi-graph G, we define the skeleton γ ( G ) of G to be the simple graph obtained by removing all self-loops and multiple edges from the graph G. For a rooted graph G with root r G , we define the rooted skeleton γ ( G ) of G to be the rooted simple graph obtained by removing all self-loops from G with root r G .
Let n 1 and Δ 0 be two integers. We denote by H ( n , Δ ) a maximal set of mutually non-isomorphic rooted graphs with a tree skeleton, n vertices, and Δ self-loops. Let H be a rooted graph in H ( n , Δ ) . For a vertex v V ( H ) , let H v denote the subgraph of H rooted at v induced by v and its descendants in the rooted skeleton γ ( H ) . For a vertex v N H ( r H ) of root r H of H, we call the subgraph H v a root-subgraph of H.
Let n 1 and Δ 0 be two integers and H be a rooted graph in H ( n , Δ ) . An ordered graph ( H , π ) of H is defined to be the rooted graph H with a left-to-right ordering π on the children of each vertex of the rooted skeleton γ ( H ) . Let K = ( H , π ) be an ordered graph of H. For a vertex v V ( K ) , we define the ordered subgraph K v of K to be a subgraph of K rooted at v induced by v and its descendants in the rooted skeleton γ ( K ) with preserving the ordering π on the children of each vertex in γ ( K v ) . For a vertex v N K ( r K ) , we call the ordered subgraph K v an ordered root-subgraph of K.
For an ordered tree, we discuss two vertex orderings: depth first search (DFS) ordering [22] and sibling-depth first search (SDFS) ordering. In DFS ordering, we index the vertices of a given ordered tree starting from the root and visiting them from left to right. Masui et al. [23] introduced the SDFS ordering for simple ordered trees. For an ordered tree T = ( L , π ) with n vertices and a left-to-right ordering π , the SDFS ordering is defined to be a vertex ordering obtained by indexing the vertices from the set { 1 , 2 , , n } such that:
(i)
the root has index one;
(ii)
all siblings are indexed consecutively according to the left-to-right ordering π ; and
(iii)
all descendants of a vertex v are indexed consecutively with indices larger than that of v and smaller than the indices of the descendants of any vertex u, which is not a descendant of v with index larger than v.
Examples of an ordered tree and its vertex indexing in DFS and SDFS ordering are illustrated in Figure 3.
Let A = ( a 1 , a 2 , , a n ) and B = ( b 1 , b 2 , , b m ) be two sequences over integers. We say that the sequence A is lexicographically smaller A B than the sequence B if there exists an integer , 1 min { n , m } , such that for each integer i, 1 i , it holds that a i = b i and:
(i)
either = n with n < m or
(ii)
< min { n , m } with a + 1 < b + 1 .
In such a case, we say that the sequence B is lexicographically greater B A than the sequence A. We define the concatenation A B of the sequences A and B to be the sequence ( a 1 , , a n , b 1 , , b m ) .

3. Enumeration of Graphs with a Tree Skeleton and a Given Number of Vertices and Self-Loops

For two integers n 1 and Δ 0 , the aim of this section is to present a method to generate all rooted graphs in H ( n , Δ ) . The idea of our enumeration method is to generate a rooted graph H H ( n , Δ ) by generating a canonical ordered graph of H. To achieve this, we define a canonical graph of a rooted graph H H ( n , Δ ) and represent the canonical ordered graph with a sequence by using its ordered subgraphs. Finally, generate the canonical ordered graph of a rooted graph by using the sequence representation of the canonical ordered graph.
We next present a canonical representation of rooted graphs in H ( n , Δ ) based on a generalization of the canonical representation of simple rooted trees with n vertices introduced by Masui et al. [23]. Recall that H ( n , 0 ) denote a maximal set of all mutually rooted non-isomorphic simple rooted trees with n vertices. Further, note that for Δ 1 , it is necessary for a canonical representation of a rooted graph H H ( n , Δ ) to contain the information of vertices and self-loops in H.
Let H be a rooted graph in H ( n , Δ ) and r H denote its root. Further, let K = ( H , π ) be an ordered graph of H with a left-to-right ordering π . For an integer i [ 1 , n ] and i-th vertex v i of K following the SDFS ordering on the rooted skeleton γ ( K ) , let K ( i ) denote the ordered subgraph K v i of K for convenience.
We introduce a canonical representation of K by using the information of the number of vertices and self-loops in the ordered subgraphs of K. For the vertices { v 1 , v 2 , , v n } of K indexed by SDFS ordering on the rooted skeleton γ ( K ) , we define the sequence representation SR(K) of K to be a sequence of the size of each ordered subgraph K ( i ) , integer i [ 2 , n ] , of K:
SR ( K ) ( s ( K ( 2 ) ) , s ( K ( 3 ) ) , , s ( K ( n ) ) ) .
Examples of a rooted graph H H ( 11 , 3 ) , an ordered graph K = ( H , π ) of H with a left-to-right ordering π , and vertices indexed in SDFS ordering and canonical representation SR ( K ) of K are illustrated in Figure 4a–c.
The next lemma states that the sequence representation of an ordered graph K is a concatenation of:
(i)
a sequence of the size of the root-subgraphs of K in the left-to-right ordering and
(ii)
the sequence representation of all root-subgraphs of K following the left-to-right ordering.
Lemma 1.
Let K be an ordered graph with n 1 vertices and Δ 0 self-loops. For integers d = deg K ( r K ) and i [ 1 , d ] , let K i denote the i-th root-subgraph of K in the left-to-right ordering. Then, it holds that:
SR ( K ) = ( s ( K 1 ) , , s ( K d ) ) SR ( K 1 ) SR ( K d ) .
Proof. 
We know that in SDFS ordering, the root vertex is indexed by one, and the siblings of a vertex are indexed consecutively. This implies that the subsequence of the first d entries of SR ( K ) is equal to ( s ( K 1 ) , , s ( K d ) ) . Furthermore, for an integer i = 2 (resp., i [ 3 , d + 1 ] ), the SDFS ordering assigns the index to the descendants of the i-th vertex consecutively and greater than the indices of the children (resp., descendants) of the ( i 1 ) -th vertex. From this, it follows that for an integer i = 2 (resp., i [ 3 , d + 1 ] ), the entries of SR ( K ( i ) ) appear consecutively after the entries of the sequence s ( K 1 ) , , s ( K d ) (resp., SR ( K ( i 1 ) ) ) in SR ( K ) . This implies that for an integer i [ 1 , d ] , the subsequence of SR ( K ) consisting of n ( K i ) 1 consecutive entries starting from d + 1 h i 1 n ( K h ) ( i 1 ) + 1 is actually SR ( K i ) . Hence, it follows that SR ( K ) = ( s ( K 1 ) , , s ( K d ) ) SR ( K 1 ) SR ( K d ) . □
For the ordered graph K in Figure 4c, SR ( K ) = ( ( 4 , 1 ) , ( 2 , 0 ) , ( 4 , 2 ) , ( 1 , 0 ) , ( 1 , 1 ) , ( 1 , 0 ) , ( 1 , 0 ) , ( 2 , 0 ) , ( 1 , 1 ) , ( 1 , 0 ) ) and deg K ( r K ) = 3 . This implies that K has three root-subgraphs K 1 , K 2 m and K 3 following the left-to-right ordering. From Figure 4c, we have ( s ( K 1 ) , s ( K 2 ) , s ( K 3 ) ) = ( ( 4 , 1 ) , ( 2 , 0 ) , ( 4 , 2 ) ) , SR ( K 1 ) = ( ( 1 , 0 ) , ( 1 , 1 ) , ( 1 , 0 ) ) , SR ( K 2 ) = ( ( 1 , 0 ) ) , and SR ( K 3 ) = ( ( 2 , 0 ) , ( 1 , 1 ) , ( 1 , 0 ) ) . Thus, we see that SR ( K ) = ( s ( K 1 ) , s ( K 2 ) , s ( K 3 ) ) SR ( K 1 ) SR ( K 2 ) SR ( K 3 ) .
We rephrase the recursion in Lemma 1 for a sequence of pairs in the following paragraph and claim that this recursion is a sufficient condition for a sequence of pairs to be the sequence representation of some ordered graph. We prove this claim in Theorem 1.
Let n 1 and Δ 0 be two integers and  M = ( ( a 1 , b 1 ) , ( a 2 , b 2 ) , , ( a n 1 , b n 1 ) ) be a sequence of pairs of integers with a i 1 and b i 0 , integer i [ 1 , n 2 ] . We say that the sequence M is ( n , Δ ) -admissible if either n = 1 or:
(i)
there exists an integer d [ 1 , n 1 ] such that n 1 = 1 i d a i with Δ 1 i d b i  and
(ii)
for each integer i [ 1 , d ] , the subsequence of M consisting of a i 1 consecutive entries starting from d + 1 h i 1 a h ( i 1 ) + 1 is ( a i , b i ) -admissible.
Theorem 1.
Let n 1 and Δ 0 be two integers and M = ( ( a 1 , b 1 ) , ( a 2 , b 2 ) , , ( a n 1 , b n 1 ) ) be a sequence of pairs of integers with a i 1 and b i 0 , integer i [ 1 , n 2 ] .
(i)
Sequence M is the sequence representation SR ( K ) of some ordered graph K with n vertices and Δ self-loops if and only if M is ( n , Δ ) -admissible.
(ii)
Whether M is admissible or not can be tested in O ( n ) time.
(iii)
When M is ( n , Δ ) -admissible, the  ordered graph K with SR ( K ) = M can be constructed in O ( n )  time.
Proof. 
For sequence M with an integer d [ 1 , n 1 ] such that n 1 = 1 i d a i and Δ 1 i d b i , let  M i denote the subsequence of M consisting of a i 1 consecutive entries starting from d + 1 h i 1 a h ( i 1 ) + 1 . For an ordered graph K and integer i [ 1 , deg K ( r K ) ] , let K i denote the i-th root-subgraph of K in the left-to-right ordering.
(i)
The if-part: Suppose that M = SR ( K ) for some ordered graph K with n vertices and Δ self-loops. If n = 1 , then M is ( 1 , Δ ) -admissible by the definition of admissibility. Let us assume that n 2 . Then, for d = deg K ( r K ) , it holds that n 1 = 1 i d n ( K i ) and Δ 1 i d s ( K i ) . Further, by Lemma 1 for each integer i [ 1 , d ] , the subsequence M i of M is equal to SR ( K i ) . Thus, by recursively using Lemma 1 for SR ( K i ) , i [ 1 , d ] , we see that the sequence representation SR ( K i ) is ( n ( K i ) , s ( K i ) ) -admissible. Hence, it follows that the sequence representation SR ( K ) is ( n , Δ ) -admissible.
The only-if part: We prove the converse of (i) by induction on n.
For n = 1 , M is ( 1 , Δ ) -admissible by the definition of admissibility. Note that M is an empty sequence in this case. Let K be an ordered graph with n = 1 vertices and Δ self-loops. Then, SR ( K ) is an empty sequence, and hence, M = SR ( K ) .
Suppose that the converse of (i) holds for any positive integer . We show that the converse holds for the integer + 1 . Let M be ( + 1 , Δ ) -admissible. Then, by the definition of admissibility, there exists an integer d [ 1 , ] such that = 1 i d a i and Δ 1 i d b i . This implies that for an integer i [ 1 , d ] , we have a i . Further, for each integer i [ 1 , d ] , the subsequence M i is ( a i , b i ) -admissible by the admissibility of M. This and the inductive hypothesis that the converse of (i) holds for any integer 1 imply that for each integer i [ 1 , d ] , there exists an ordered graph H with a i vertices and b i self-loops such that M i = SR ( H ) . Let K denote the ordered graph with + 1 vertices, Δ self-loops, deg K ( r K ) = d , Δ 1 i d b i self-loops on the root r K , and the  i-th root subgraph K i of K be the ordered subgraph H such that M i = SR ( H ) . Then, it immediately follows that:
SR ( K ) = ( s ( K 1 ) , , s ( K d ) ) M 1 M 2 M d .
This means that M = SR ( K ) holds, since ( ( a 1 , b 1 ) , , ( a d , b d ) ) = ( s ( K 1 ) , , s ( K d ) ) , showing that the converse holds for the integer + 1 .
Hence, by mathematical induction, the converse of (i) holds for any integer  n 1 .
(ii)
 We prove this result by induction on n.
For n = 1 , the sequence M is an empty sequence and is ( 1 , Δ ) -admissible by the definition of admissibility. Therefore, it takes constant O ( 1 ) time to test admissibility in this case.
Suppose that for n = , 1 , the admissibility of sequence M can be tested in O ( ) time. We show that the statement (ii) holds for n = + 1 . To show if M is ( + 1 , Δ ) -admissible, we need to find an integer d [ 1 , ] such that = 1 i d a i and Δ 1 i d b i . Such an integer d can be identified in O ( d ) time. Suppose that such an integer d exists for M. Then, for each integer i [ 1 , d ] , we next need to test if the subsequence M i is ( a i , b i ) -admissible. Note that the size of the sequence M i is a i 1 , i [ 1 , d ] . By = 1 i d a i , it holds that a i , i [ 1 , d ] . This and the inductive hypothesis imply that for an integer i [ 1 , d ] , the admissibility of the sequence M i can be tested in O ( a i ) time. Thus, the time testing admissibility of M is O ( d + 1 i d a i ) = O ( d + ) = O ( + 1 ) , since d .
Hence, by mathematical induction, the admissibility of a sequence M of size n 1 , n 1 can be tested in O ( n ) time.
(iii)
We prove the claim in (iii) by induction on n.
For n = 1 , M is ( 1 , Δ ) -admissible and is the sequence representation of the ordered graph K with only one vertex and Δ self-loops. This implies that K can be constructed in O ( 1 ) time.
Suppose that for n = , 1 , the  statement (iii) holds. We show that the statement (iii) holds for n = + 1 . Let M be an ( + 1 , Δ ) -admissible sequence. Then, there exists an integer d [ 1 , ] , such that = 1 i d a i and Δ 1 i d b i . By (i), there exists an ordered graph K with n vertices and Δ self-loops such that SR ( K ) = M . Thus, it holds that deg K ( r K ) = d . Further, by Lemma 1, for each integer i [ 1 , d ] , the i-th root-subgraph K i of K has a i vertices and b i self-loops. Observe that such an integer d exists uniquely due to the admissibility of M. This implies that deg K ( r K ) can be obtained in O ( d ) time.
By SR ( K ) = M and Lemma 1, for each integer i [ 1 , d ] , it holds that SR ( K i ) = M i . Recall that the size of SR ( K i ) is n ( K i ) 1 , which is equal to a i 1 , i [ 1 , d ] . Further, by = 1 i d a i , it follows that a i , i [ 1 , d ] . Thus, by the inductive hypothesis for an integer i [ 1 , d ] , the subgraph K i can be constructed from M i in O ( a i ) time. Since d + 1 i d a i = d + and d , K can be constructed in O ( + 1 ) time from M.
Hence, by mathematical induction, for integers n 1 and Δ 0 and an ( n , Δ ) -admissible sequence M, the ordered graph K with SR ( K ) = M can be constructed by M in O ( n ) time. □
Let M = ( ( a 1 , b 1 ) , ( a 2 , b 2 ) , , ( a n 1 , b n 1 ) ) be an ( n , Δ ) -admissible sequence. Then, there exists an integer d [ 1 , n 1 ] such that n 1 = 1 i d a i . Furthermore, by Theorem 1(i), there exists an ordered graph K with n vertices and Δ self-loops such that deg K ( r K ) = d and SR ( K ) = M . Note that such an integer d and ordered graph K are unique. We call the integer d the root-degree of M and denote it by d ( M ) . Moreover, for each integer i [ 1 , d ( M ) ] , the subsequence of M consisting of a i 1 consecutive entries starting from d ( M ) + 1 h i 1 a h ( i 1 ) + 1 is equal to the sequence representation of the i-th root-subgraph of M. For an integer i [ 1 , d ( M ) ] , we call such a subsequence of M the i-th root-subsequence of M and denote it by M ( i ) .
By Theorem 1(i), it follows that an ordered graph K with n 1 vertices and Δ 0 self-loops can be completely determined by SR ( K ) . Thus, we define a canonical representation of a rooted graph H H ( n , Δ ) as follows. For a rooted graph H H ( n , Δ ) , we define the canonical representation to be an ( n , Δ ) -admissible sequence M such that M is lexicographically maximum among all ( n , Δ ) -admissible sequences that are the sequence representation of ordered graphs of H.
In Figure 4d, we show the canonical representation M of the rooted graph H H ( 11 , 3 ) illustrated in Figure 4a. Further, we show the ordered graph L such that SR ( L ) = M .
To generate all rooted graphs in H ( n , Δ ) , it is enough to generate the canonical representation of each rooted graph H H ( n , Δ ) by Theorem 1(i). For two integers n 1 and Δ 0 , let M ( n , Δ ) denote the set of all ( n , Δ ) -admissible sequences that are canonical representation of graphs in H ( n , Δ ) . Note that the empty sequence is the only sequence in M ( 1 , Δ ) . In the next lemma, we give a characterization of sequences in M ( n , Δ ) .
Lemma 2.
Let n 2 and Δ 0 be two integers. Let M = ( ( a 1 , b 1 ) , ( a 2 , b 2 ) , , ( a n 1 , b n 1 ) ) be a sequence of integer pairs with an integer d [ 1 , n 1 ] such that n 1 = 1 i d a i . For an integer i [ 1 , d ] , let M ( i ) denote the subsequence of M consisting of a i 1 consecutive entries starting from d + 1 h i 1 a h ( i 1 ) + 1 . Then, M M ( n , Δ ) if and only if the following hold:
(i)
a i 1 , i [ 1 , d ] , 1 i d a i = n 1 and a i a i + 1 , i [ 1 , d 1 ] ;
(ii)
b i 0 , i [ 1 , d ] , 1 i d b i Δ and for each integer i [ 1 , d 1 ] such that a i = a i + 1 , it holds that b i b i + 1 ; and
(iii)
M ( i ) M ( a i , b i ) , i [ 1 , d ] , and for each integer i [ 1 , d 1 ] such that a i = a i + 1 and b i = b i + 1 , it holds that M ( i ) M ( i + 1 ) .
Proof. 
The if part: Let M M ( n , Δ ) . Then, by the definition of admissibility, it holds that d = d ( M ) . Let H denote the ordered graph with n vertices and Δ self-loops such that SR ( H ) = M .
(i)
By the admissibility of M, we have a i 1 , i [ 1 , d ( M ) ] , 1 i d ( M ) a i = n 1 . Furthermore, M is the canonical representation of H, and therefore, for the sequence representation ( ( s 1 , s 1 ) , ( s 2 , s 2 ) , , ( s n 1 , s n 1 ) ) of any ordered graph of H, it holds that ( a 1 , , a d ( M ) ) ( s 1 , , s d ( M ) ) . This eventually implies that a i a i + 1 , i [ 1 , d 1 ] .
(ii)
By the admissibility of M, it holds that b i 0 , i [ 1 , d ( M ) ] , 1 i d ( M ) b i Δ . Moreover, for the sequence representation ( ( s 1 , s 1 ) , ( s 2 , s 2 ) , , ( s n 1 , s n 1 ) ) of any ordered graph of H such that s i = a i , i [ 1 , d ( M ) ] , it holds that ( b 1 , , b d ( M ) ) ( s 1 , , s d ( M ) ) since M is the canonical representation of H. This implies that for each integer i [ 1 , d ( M ) 1 ] such that a i = a i + 1 , it holds that b i b i + 1 .
(iii)
We first prove that for each integer i [ 1 , d ( M ) ] , it holds that M ( i ) M ( a i , b i ) .
For an integer i [ 1 , d ( M ) ] , let H i denote the i-th root-subgraph of H following the left-to-right ordering. Then, by Lemma 1 for each integer i [ 1 , d ( M ) ] , it holds that SR ( H i ) = M ( i ) .
Suppose on the contrary that there exists an integer i [ 1 , d ( M ) ] such M ( i ) M ( a i , b i ) . This means that there exists an ordered graph L that is rooted isomorphic to H i , and SR ( L ) M ( i ) holds. Let M denote the sequence obtained from M by replacing the subsequence M i with SR ( L ) . Clearly, M is ( n , Δ ) -admissible, and M M holds by the construction of M . Let H denote the ordered graph obtained by replacing H i with L in H and preserving the ordering of the children of each vertex in L. Then, we see that H is rooted isomorphic to H, and SR ( H ) = M . This contradicts the fact that M is a sequence in M ( n , Δ ) . Hence, for each integer i [ 1 , d ( M ) ] , it holds that M ( i ) M ( a i , b i ) .
Recall that M is the canonical representation of H. This implies that for the sequence representation ( ( s 1 , s 1 ) , ( s 2 , s 2 ) , , ( s n 1 , s n 1 ) ) of any ordered graph of H such that ( s i , s i ) = ( a i , b i ) , i [ 1 , d ( M ) ] , it holds that ( ( a d ( M ) + 1 , b d ( M ) + 1 ) , , ( a n 1 , b n 1 ) ) ( ( s d ( M ) + 1 , s d ( M ) + 1 ) , , ( s n 1 , s n 1 ) ) . This implies that for each integer i [ 1 , d ( M ) 1 ] such that a i = a i + 1 and b i = b i + 1 , we have M ( i ) M ( i + 1 ) .
The only-if part: Let M satisfy (i), (ii), and (iii). We show that M M ( n , Δ ) . To prove this, we show that M is a canonical representation of some graph in H ( n , Δ ) .
By (i) and (ii), we have a i 1 , b i 0 , i [ 1 , d ] , n 1 = 1 i d a i and Δ 1 i d b i . Furthermore, for each integer i [ 1 , d ] , the sequence M i is ( a i , b i ) -admissible, since M ( i ) M ( a i , b i ) by (iii). This implies that M is ( n , Δ ) -admissible.
By Theorem 1(i), there exists a unique ordered graph K = ( H , π ) such that SR ( K ) = M for some H H ( n , Δ ) . This implies that deg K ( r K ) = d , and for each integer i [ 1 , d ] , the i-th root subgraph of K has a i vertices and b i self-loops. This implies that any ordered graph L that is rooted isomorphic to K has x vertices and y self-loops such that ( x , y ) = ( a i , b i ) for some i [ 1 , d ] .
The condition a i a i + 1 , i [ 1 , d 1 ] in (i) implies that for the sequence representation S = ( ( s 1 , s 1 ) , ( s 2 , s 2 ) , , ( s n 1 , s n 1 ) ) of any ordered graph that is rooted isomorphic to K, it holds that M S since ( a 1 , , a d ) ( s 1 , , s d ) . For the condition for each integer i [ 1 , d 1 ] such that a i = a i + 1 , it holds that b i b i + 1 in (ii) implies that for the sequence representation S = ( ( s 1 , s 1 ) , ( s 2 , s 2 ) , , ( s n 1 , s n 1 ) ) of any ordered graph that is rooted isomorphic to K such that s i = a i , i [ 1 , d ] , it holds that M S since ( b 1 , , b d ) ( s 1 , , s d ) . Finally, for the condition for each integer i [ 1 , d 1 ] such that a i = a i + 1 and b i = b i + 1 , it holds that M ( i ) M ( i + 1 ) in (iii) implies that for the sequence representation S = ( ( s 1 , s 1 ) , ( s 2 , s 2 ) , , ( s n 1 , s n 1 ) ) of any ordered graph that is rooted isomorphic to K and ( s i , s i ) = ( a i , b i ) , i [ 1 , d ] , it holds that M S since ( ( a d + 1 , b d + 1 ) , , ( a n 1 , b n 1 ) ) ( ( s d + 1 , s d + 1 ) , , ( s n 1 , s n 1 ) ) . This eventually implies that M is the canonical representation of H from which it follows that M M ( n , Δ ) . □
We next give the structure of the sequences that are lexicographically minimum and maximum among all sequences in M ( n , Δ ) .
Lemma 3.
Let n 2 and Δ 0 be two integers.
(i)
The sequences N = ( ( 1 , 0 ) , ( 1 , 0 ) , , ( 1 , 0 ) ) and M = ( ( n 1 , Δ ) , ( n 2 , Δ ) , , ( 1 , Δ ) ) each of length n 1 are lexicographically minimum and maximum among all sequences in M ( n , Δ ) , respectively.
(ii)
Whether a sequence in M ( n , Δ ) is lexicographically minimum or maximum among all sequences in M ( n , Δ ) can be tested in O ( n ) .
Proof. 
(i)
It is easy to observe that the sequence N is ( n , Δ ) -admissible. Furthermore, for two integers i 2 and j 0 , the ranges of the first and the second entries in any sequence in M ( i , j ) are [ 1 , i 1 ] and [ 0 , j ] , respectively. This implies that the sequence N is lexicographically minimum among all the sequences in M ( n , Δ ) . Moreover, the sequence ( ( 1 , Δ ) ) is admissible and lexicographically maximum among all the sequences in M ( 2 , Δ ) . From this, it follows that the sequence ( ( 2 , Δ ) , ( 1 , Δ ) ) is admissible and lexicographically maximum among all the sequences in M ( 3 , Δ ) . Thus, by using this inductive argument, we can conclude that the sequence M is admissible and lexicographically maximum among all the sequences in M ( n , Δ ) .
(ii)
We know that a sequence S in M ( n , Δ ) is of length n 1 , and therefore, by using a for-loop of size n 1 and (i), we can test if S is lexicographically minimum or maximum among all sequences in M ( n , Δ ) in O ( n ) time.
 □
Let S ( n , Δ ) and L ( n , Δ ) denote the lexicographically minimum and maximum sequences among all sequences in M ( n , Δ ) , respectively.
For a sequence M M ( n , Δ ) such that M S ( n , Δ ) , we define the predecessor P ( M ) of M to be the sequence that is lexicographically maximum among all sequences that are lexicographically smaller than M, i.e., there does not exist a sequence N M ( n , Δ ) \ { P ( M ) } such that M N P ( M )  holds.
For a sequence M M ( n , Δ ) , we next give the structure of the predecessor P ( M ) , if it exists, of M.
Theorem 2.
Let n 2 and Δ 0 be two integers and M = ( ( a 1 , b 1 ) , ( a 2 , b 2 ) , , ( a n 1 , b n 1 ) ) be a sequence in M ( n , Δ ) . Let d denote the root-degree of M. Then, for the predecessor P ( M ) = ( ( x 1 , y 1 ) , ( x 2 , y 2 ) , , ( x n 1 , y n 1 ) ) , if it exists, we have:
(a)
If a i = 1 and b i = 0 , i [ 1 , d ] , then P ( M ) does not exist.
(b)
If a i 1 for some i [ 1 , d ] b j = 0 and M ( j ) = S ( a j , b j ) , j [ 1 , d ] . Then, for the largest integer k [ 1 , d ] such that a k 1 , it holds that d(P ( M ) ) = k 1 + ( a k + d k ) / ( a k 1 ) , y 1 = Δ , y i = 0 , i [ 2 , d ( P ( M ) ) ] , x i = a i , i [ 1 , k 1 ] , x i = a k 1 , i [ k , d ( P ( M ) ) 1 ] , x d ( P ( M ) ) = a k + d k ( a k + d k ) / ( a k 1 ) ( a k 1 ) , and P ( M ) ( i ) = L ( x i , y i ) , i [ 1 , d ( P ( M ) ) ] .
(c)
If b i 0 for some i [ 1 , d ] , M ( j ) = S ( a j , b j ) , j [ 1 , d ] . For the largest integer k [ 1 , d ] such that b k 0 , let p max { i d a k = a k + i } , q p + 1 if b k = 1 , and q ( Δ 1 i k 1 b i ) / ( b k 1 ) if b k 2 and t min { q , p + 1 } . Then, it holds that d(P ( M ) ) = d , x i = a i , i [ 1 , d ] , y i = b i , i [ 1 , k 1 ] , y k = b k 1 ; for  k d , we have y k + i = b k 1 , i [ 1 , t 1 ] , y k + t = ( Δ 1 i k 1 b i ) t ( b k 1 ) , y i = 0 , i [ k + t + 1 , d ] , and P ( M ) ( i ) = L ( x i , y i ) , i [ 1 , d ] .
(d)
Otherwise if a i 1 , b j 0 , M ( ) S ( a , b ) , for some i , j , [ 1 , d ] . For the largest integer k [ 1 , d ] such that M ( k ) S ( a k , b k ) , let p max { i d a k = a k + i and b k = b k + 1 } . Then, it holds that d(P ( M ) ) = d , ( x i , y i ) = ( a i , b i ) , i [ 1 , d ] , P ( M ) ( i ) = M ( i ) , i [ 1 , k 1 ] , P ( M ) ( k + i ) = P ( M ( k ) ) , i [ 0 , p ] , and P ( M ) ( i ) = L ( a i , b i ) , i [ k + p + 1 , d ] .
Proof. 
(a)
If a i = 1 and b i = 0 , i [ 1 , d ] , then it holds that d = n 1 . Thus, by Lemma 3(i), it holds that M = S ( n , Δ ) , and therefore, P ( M ) does not exist.
(b)
If a i 1 for some i [ 1 , d ] b j = 0 and M ( j ) = S ( a j , b j ) , j [ 1 , d ] , then M is lexicographically minimum among all those sequences ( ( c 1 , c 1 ) , , ( c n 1 , c n 1 ) ) M ( n , Δ ) for which it holds that c i = a i , i [ 1 , d ] . Further, a i 1 for some i [ 1 , d ] implies that P ( M ) exists. By the definition of a predecessor, observe that P ( M ) is lexicographically maximum among all those sequences S = ( ( s 1 , s 1 ) , , ( s n 1 , s n 1 ) ) M ( n , Δ ) for which it holds that s i = x i , i [ 1 , d ( P ( M ) ) ] . This implies that for each such sequence S, it holds that either ( y 1 , y 2 , , y d ( P ( M ) ) ) ( s 1 , s 2 , , s d ( P ( M ) ) ) or y i = s i and P ( M ) ( i ) S ( i ) , i [ 1 , d ( P ( M ) ) ] . The former implies that y 1 = Δ , y i = 0 , i [ 2 , d ( P ( M ) ) ] , while the latter implies that P ( M ) ( i ) = L ( x i , y i ) , i [ 1 , d ( P ( M ) ) ] . Further, the sequence ( x 1 , , x d ( P ( M ) ) ) satisfies Lemma 2(i), and there does not exist a sequence L that satisfies Lemma 2(i) such that ( x 1 , , x d ( P ( M ) ) ) L ( a 1 , , a d ) holds by the definition of P ( M ) . This and the definition of k imply that x i = a i , i [ 1 , k 1 ] ; the sequence ( x k , x k + 1 , , x d ( P ( M ) ) ) is a non-decreasing sequence, and there there does not exist a sequence Z = ( z 1 , , z t ) such that z i [ 1 , a k 1 ] , i [ 1 , t ] and 1 i t z i = k j d a j for which it holds that ( x k , , x d ( P ( M ) ) ) Z ( a k , , a d ) holds. This eventually implies that d(P ( M ) ) = k 1 + k i d a i / ( a k 1 ) , x i = a k 1 , i [ k , d ( P ( M ) ) 1 ] , and x d ( P ( M ) ) = k i d a i k i d a i / ( a k 1 ) ( a k 1 ) . Thus, by the definition of k, we have k i d a i = a k + d k , and therefore, we have the required result.
(c)
If b i 0 for some i [ 1 , d ] and M ( j ) = S ( a j , b j ) , j [ 1 , d ] , then M is lexicographically minimum among all those sequences ( ( c 1 , c 1 ) , , ( c n 1 , c n 1 ) ) M ( n , Δ ) for which it holds that ( c i , c i ) = ( a i , b i ) , i [ 1 , d ] . Since b i 0 for some i [ 1 , d ] , therefore P ( M ) exists and is lexicographically maximum among all those sequences ( ( s 1 , s 1 ) , , ( s n 1 , s n 1 ) ) M ( n , Δ ) for which it holds that ( s i , s i ) = ( a i , y i ) , i [ 1 , d ( P ( M ) ) ] . This implies that x i = a i , i [ 1 , d ( P ( M ) ) ] , and therefore, we have d ( P ( M ) ) = d . Furthermore, ( y 1 , y 2 , , y d ) ( s 1 , s 2 , , s d ) and P ( M ) ( i ) S ( i ) , i [ 1 , d ] . This implies that for each integer i [ 1 , d ] , it holds that P ( M ) ( i ) = L ( a i , y i ) , and the sequence ( y 1 , y 2 , , y d ) is lexicographically minimum among all those sequences that satisfy Lemma 2(ii) and are lexicographically smaller than ( b 1 , b 2 , , b d ) . This and the definition of k imply that y i = b i , i [ 1 , k 1 ] ; by Lemma 2(ii), the sequence ( y k , y k + 1 , , y k + p ) is a non-decreasing sequence, and there does not exist a sequence Z = ( z k , z k + 1 , , z k + p ) such that z i [ 0 , b k 1 ] and k i k + p z i = min { ( p + 1 ) ( b k 1 ) , Δ 1 i k 1 b i } for which it holds that ( y k , y k + 1 , x k + p ) Z ( b k , b k + 1 , , b k + p ) . This eventually implies that y k = b k 1 and for k d y k + i = b k 1 , i [ 1 , t 1 ] . This and the minimality of ( y 1 , y 2 , , y d ) imply that y k + t = ( Δ 1 i k 1 b i ) t ( b k 1 ) and y i = 0 , i [ k + t + 1 , d ] .
(d)
The conditions of this case imply that M is not the lexicographically minimum among all those sequences ( ( c 1 , c 1 ) , , ( c n 1 , c n 1 ) ) M ( n , Δ ) for which it holds that ( c i , c i ) = ( a i , b i ) , i [ 1 , d ] . This implies that for P ( M ) , it holds that d(P ( M ) ) = d and ( x i , y i ) = ( a i , b i ) , i [ 1 , d ] , and there does not exist a sequence S = ( ( s 1 , s 1 ) , , ( s n 1 , s n 1 ) ) M ( n , Δ ) for which it holds that ( s i , s i ) = ( a i , b i ) , i [ 1 , d ] and ( ( x 1 , y 1 ) , , ( x n 1 , y n 1 ) ) S M . This implies that for each such sequence S, it holds that P ( M ) ( 1 ) P ( M ) ( 2 ) P ( M ) ( d ) S ( 1 ) S ( 2 ) S ( d ) . This and the definition of k imply that P ( M ) ( i ) = M ( i ) , i [ 1 , k 1 ] . Furthermore, by Lemma 2(iii) and the definition of p, it holds that P ( M ) ( i ) P ( M ) ( i + 1 ) , i [ k , k + p 1 ] , and there does not exist a sequence S = ( ( s 1 , s 1 ) , , ( s n 1 , s n 1 ) ) M ( n , Δ ) such that ( s i , s i ) = ( a i , b i ) , i [ 1 , d ] and S ( i ) S ( i + 1 ) , i [ k , k + p 1 ] for which it holds that P ( M ) ( k ) P ( M ) ( k + 1 ) P ( M ) ( K + 1 ) S ( k ) S ( k + 1 ) S ( k + p + 1 ) M ( k ) M ( k + 1 ) M ( k + p + 1 ) . Since  M ( k ) S ( a k , b k ) , therefore P ( M ) ( k ) is a lexicographically minimum sequence in M ( a k , b k ) for which it holds that P ( M ) ( k ) M ( k ) . This implies that P ( M ) ( k + i ) = P ( M ( k ) ) , i [ 0 , p ] . Further, by the minimality of P ( M ) , P ( M ) ( i ) = L ( a i , b i ) , i [ k + p + 1 , d ] .
Finally, one can easily verify that the sequence ( ( x 1 , y 1 ) , , ( x n 1 , y n 1 ) ) obtained in each of the above cases satisfies Lemma 2(i)–(iii) by construction, and hence, ( ( x 1 , y 1 ) , , ( x n 1 , y n 1 ) ) is an element of M ( n , Δ ) that is P ( M ) , which completes the proof. □
Lemma 4.
Let n 2 and Δ 0 be two integers and M be a sequence in M ( n , Δ ) . Then, the predecessor P ( M ) , if it exits, can be computed in O ( n ) time and O ( n ) space.
The proof of Lemma 4 follows from Algorithm 1 and Lemma 5.
We next present Algorithm 1 to compute the predecessor based on Theorem 2. In this algorithm, for a sequence M M ( n , Δ ) with root-degree d and integer i [ 1 , d ] , the variable M [ i ] stores the i-th root-subsequence M ( i ) of M, and the variable P [ M ] stores the predecessor, if it exists, of M.
Algorithm 1 Computing the predecessor of an admissible sequence.
Input: Two integers n 2 and Δ 0 and an ( n , Δ ) -admissible sequence M = ( ( a 1 , b 1 ) , , ( a n 1 , b n 1 ) ) .
Output: The predecessor M if it exists; The predecessor of M does not exist otherwise.
1: d : = The root-degree of M;
2:if If a i = 1 and b i = 0 , i [ 1 , d ] then
3: Output The predecessor of M does not exist /* Theorem 2(a) */
4:else/* The predecessor of M exists by Theorem 2*/
5: P [ M ] : = ( ( x 1 , y 1 ) , , ( x n 1 , y n 1 ) )
6:  if a i 1 for some i [ 1 , d ] , and  b j = 0 and M [ j ] = S ( a j , b j ) , j [ 1 , d ] then
   /* Theorem 2(b) */
7:   k : = max { i a i 1 } ; h : = k 1 + ( a k + d k ) / ( a k 1 ) ; /* The root-degree
   d ( P ( M ) ) of P ( M ) */
8:   y 1 : = Δ ; y i : = 0 , i [ 2 , h ] ; x i : = a i , i [ 1 , k 1 ] ; x i : = a k 1 , i [ k , h 1 ] ;
    x h : = a k + d k ( a k + d k ) / ( a k 1 ) ( a k 1 ) ; P [ M ] [ i ] = L ( x i , y i ) , i [ 1 , h ] .
9: else if b i 0 for some i [ 1 , d ] and M [ j ] = S ( a j , b j ) , j [ 1 , d ] then
   /* Theorem 2(c) */
10:   k : = max { i b i 0 } ; p : = max { i d a k = a k + i } ; q : = p + 1 if b k = 1 ;
    q : = ( Δ 1 i k 1 b i ) / ( b k 1 ) if b k 2 ; t : = min { q , p + 1 } ;
11:   x i : = a i , i [ 1 , d ] ; y i : = b i , i [ 1 , k 1 ] ; y k : = b k 1 ;
12:  if k d then
13:    y k + i : = b k 1 , i [ 1 , t 1 ] ; y k + t : = ( Δ 1 i k 1 b i ) t ( b k 1 ) ;
    y i = 0 , i [ k + t + 1 , d ]
14:  end if;
15:  P [ M ] [ i ] : = L ( x i , y i ) , i [ 1 , d ]
16: else/* If a i 1 , b j 0 and M [ ] S ( a , b ) , for some i , j , [ 1 , d ] */
   /* Theorem 2(d) */
17:   k : = max { i M [ i ] S ( a i , b i ) } ;
18:   p : = max { i d a k = a k + i and b k = b k + 1 } ;
    ( x i , y i ) : = ( a i , b i ) , i [ 1 , d ] ; P [ M ] [ i ] : = M [ i ] , i [ 1 , k 1 ] ;
19:  P [ M ] [ k ] : = Algorithm 1 ( a k , b k , M [ k ] ) ;
20:  P [ M ] [ k + i ] : = P [ M ] [ k ] , i [ 1 , p ] ; P [ M ] [ i ] : = L ( a i , b i ) , i [ k + p + 1 , d ]
21: end if
22: Output P [ M ] as the predecessor of M;
23:end if.
Lemma 5.
For two integers n 2 and Δ 0 and an ( n , Δ ) -admissible sequence M, Algorithm 1 outputs the predecessor P ( M ) , if it exits, in O ( n ) time and O ( n ) space.
Proof. 
Correctness: The correctness of Algorithm 1 immediately follows from Theorem 2.
Complexity analysis: By the definition of the root-degree, we can compute d at Line 3 in O ( n ) time.
We can test if a i 1 and b j 0 hold for some i , j [ 1 , d ] in O ( n ) time. Similarly, we can test if M ( j ) = S ( a j , b j ) , for some j [ 1 , d ] in O ( n ) time, since the length of M ( j ) is a j 1 , and 1 i d a i = n 1 . Hence, we can test the conditions at Lines 2, 6, 9, and 16 in O ( n + n ) = O ( n ) time. This implies that we can check if the predecessor of M exists in O ( n ) time. We next discuss the time complexity of computing the predecessor in each of the cases at Lines 6, 9, and 16.
When the conditions at Line 6 hold, then k and h can be computed in O ( n ) time, since k d and h d + 1 . This implies that ( ( x 1 , y 1 ) , , ( x h , y h ) ) can be computed in O ( n ) time. Furthermore, we can compute L ( x i , y i ) , i [ 1 , h ] in O ( x i ) time by Lemma 3(i). Recall that for P [ M ] , it holds that 1 i d x i = n 1 . Thus, P [ M ] can be computed in O ( n ) time.
When the conditions at Line 9 hold, then k, p , q , and t can be computed in O ( n ) time by there definitions. Thus, ( ( x 1 , y 1 ) , , ( x d , y d ) ) can be computed from Line 11 to Line 14 in O ( n ) time. Furthermore, L ( x i , y i ) , i [ 1 , d ] can be computed at Line 15 in O ( n ) time, as discussed above. This implies that P [ M ] can be computed in O ( n ) time in this case.
Finally, when the conditions at Line 16 hold, then once again, we can compute k in O ( n ) time, since 1 i d a i = n 1 . Further, p can be computed in O ( n ) time by the definition of p. However, P [ M ] [ k ] can be obtained by recursively running Algorithm 1 on a k , b k and M [ k ] . Note that this operation is repeated at most the length of the sequence P [ M [ k ] ] , which is a k 1 in this case, and hence, P [ M ] [ k ] can be computed in O ( n ) time. Once again, the computation at Line 20 can be done in O ( n ) time since it holds that 1 i d a i = n 1 . Hence, P [ M ] can be computed in O ( n ) time.
Note that the O ( n ) space is sufficient to store P [ M ] , if it exists, which completes the proof. □
Note that we can generate all rooted graphs in H ( n , Δ ) by generating their canonical representation by repeatedly using Algorithm 1 starting from the lexicographically maximum sequence L ( n , Δ ) in M ( n , Δ ) in O ( n ) time per graph and O ( n ) space in total.
Theorem 3.
Let n 2 and Δ 0 be two integers. Then, all mutually non-isomorphic graphs with n vertices, Δ self-loops, and a tree skeleton can be generated in O ( n ) time per graph and O ( n ) space in total.
Proof. 
A tree can be viewed as a rooted tree by considering its centroid as the root [24]. We know that when n is odd, then there are only trees with unicentroids; however, when n is even, then there are trees with unicentroids.
By the definition of a unicentroid, all mutually non-isomorphic graphs with n vertices, Δ self-loops, and a tree skeleton with a unicentroid can be enumerated by generating all graphs H in H ( n , Δ ) such that each root subgraph of H has at most ( n 1 ) / 2 number of vertices, i.e., by generating all sequences M = ( ( a 1 , b 1 ) , , ( a n 1 , b n 1 ) ) M ( n , Δ ) such that a i [ 1 , ( n 1 ) / 2 ] , i [ 1 , d ( P ( M ) ) ] . Let S denote the sequence that is lexicographically maximum among all those sequences in M ( n , Δ ) that represent a tree with a unicentroid. When n is even, then it holds that S = ( ( ( n 1 ) / 2 , Δ ) , ( ( n 1 ) / 2 , 0 ) , ( 1 , 0 ) ) L ( ( n 1 ) / 2 , Δ ) L ( ( n 1 ) / 2 , 0 ) L ( 1 , 0 ) . Recall that L ( 1 , 0 ) is an empty sequence, and therefore, we have S = ( ( ( n 1 ) / 2 , Δ ) , ( ( n 1 ) / 2 , 0 ) , ( 1 , 0 ) ) L ( ( n 1 ) / 2 , Δ ) L ( ( n 1 ) / 2 , 0 ) . However, when n is odd, then it holds that S = ( ( ( n 1 ) / 2 , Δ ) , ( ( n 1 ) / 2 , 0 ) ) L ( ( n 1 ) / 2 , Δ ) L ( ( n 1 ) / 2 , 0 ) . Hence, we can generate all sequences in M ( n , Δ ) that represent a graph H H ( n , Δ ) such that the skeleton of H has a unicentroid by repeatedly using Theorem 2 starting from the sequence S. This implies that we can generate all such sequences in O ( n ) time per sequence and O ( n ) space by using Algorithm 1.
When n is even, then all mutually non-isomorphic graphs with n vertices, Δ self-loops, and a tree skeleton with a bicentroid can be enumerated by generating all sequences M = ( ( a 1 , b 1 ) , , ( a n 1 , b n 1 ) ) M ( n , Δ ) such that the root-degree d ( M ) = 2 , a 1 = a 2 = n / 2 and b 1 + b 2 = Δ with b 1 b 2 . In such a case, the sequences ( ( n / 2 , Δ ) , ( n / 2 , 0 ) ) L ( n / 2 , Δ ) L ( n / 2 , 0 ) and ( ( n / 2 , Δ / 2 ) , ( n / 2 , Δ / 2 ) ) L ( n / 2 , Δ / 2 ) L ( n / 2 , Δ / 2 ) are lexicographically maximum and minimum, respectively, among all those sequences in M ( n , Δ ) that represent a graph with a bicentroid. Let M = ( ( a 1 , b 1 ) , , ( a n 1 , b n 1 ) ) M ( n , Δ ) be a sequence that represents a graph H H ( n , Δ ) such that the skeleton of H has a bicentroid and M ( ( n / 2 , Δ / 2 ) , ( n / 2 , Δ / 2 ) ) L ( n / 2 , Δ / 2 ) L ( n / 2 , Δ / 2 ) . When M ( i ) = S ( a j , b j ) , i { 1 , 2 } , then it holds that P ( M ) = ( ( a 1 , b 1 1 ) , ( a 2 , b 2 + 1 ) ) L ( a 1 , b 1 1 ) ( a 2 , b 2 + 1 ) . However, in the case otherwise, i.e., when M ( i ) S ( a j , b j ) , for some i { 1 , 2 } , then P ( M ) can be generated by using Theorem 2(d). Clearly, in both of these cases, P ( M ) can be generated in O ( n ) time and O ( n ) space. This eventually implies that all sequences that represent a graph in H ( n , Δ ) with a bicentroid can be generated in O ( n ) time per sequence and O ( n ) space by repeatedly computing the predecessor of sequences M as described above starting from ( ( n / 2 , Δ ) , ( n / 2 , 0 ) ) L ( n / 2 , Δ ) L ( n / 2 , 0 ) until M = ( ( n / 2 , Δ / 2 ) , ( n / 2 , Δ / 2 ) ) L ( n / 2 , Δ / 2 ) L ( n / 2 , Δ / 2 ) .
Hence, we can generate all non-isomorphic graphs with n vertices, Δ self-loops, and a tree skeleton with a unicentroid or bicentroid in O ( n ) time per graph and O ( n ) space in total, which completes that proof. □

4. Results and Discussion

We computed all graphs with n vertices, Δ self-loops, and a tree skeleton for different values of n and Δ to test the efficiency of our algorithm, and the results are listed in Table 1. These experiments were performed on a PC with an Intel Core i7-500 processor, running at 2.70 GHz, 16 GB of memory, and Windows 10. From the experimental results, it is evident that the proposed method is computationally efficient.
An application to the generation of polymer topologies with a tree skeleton: Observe that a graph with a tree skeleton, Δ self-loops, and no multiple edges has cycle rank Δ . Therefore, the class of such graphs contains all polymer topologies of cycle rank Δ with a tree skeleton. However, it is a natural question to search for a relationship between the number n of vertices and the number Δ of self-loops such that there exists a polymer topology with a tree skeleton, n vertices, and cycle rank Δ . Clearly, for n = 1 and Δ 2 , there exists exactly one polymer topology with a tree skeleton, n vertices, and Δ self-loops. Let P ( n , Δ ) denote a maximal set of mutually non-isomorphic polymer topologies with a tree skeleton, n vertices, Δ self-loops, and no multiple edges. Azam et al. [21] proved the following necessary condition on Δ to have a polymer topology with a tree skeleton and n vertices.
Lemma 6
([21]). If n 1 and Δ n 2 + 1 , then it holds that P ( n , Δ ) .
Let G ( n , Δ ) denote a maximal set of mutually non-isomorphic graphs with a tree skeleton, n vertices, and Δ self-loops. For an integer r 1 , let P ( r ) denote a maximal set of mutually non-isomorphic polymer topologies with a tree skeleton, n vertices, and r self-loops. By Lemma 6, it holds that:
P ( r ) = n Z + : n 2 + 1 r P ( n , r ) n Z + : n 2 + 1 r G ( n , r )
Thus, by using Equation (1) and identifying the degree of each vertex in the graphs in G ( n , r ) from their canonical representations, we can compute all polymer topologies in P ( r ) . We applied our method to generate all polymer topologies in P ( r ) for rank r = 2 , 3 , , 9 , and the results are listed in Table 2.

5. Conclusions

We proposed an efficient method to enumerate all mutually non-isomorphic graphs with a tree skeleton, a given number of vertices, and the number of self-loops. The idea of this method is to generate rooted graphs with n vertices and Δ self-loops by generating their canonical representation. We defined the canonical representation of a rooted graphs H with n vertices and Δ self-loops based on the ordered graphs of H. The proposed method generates all graphs with a tree skeleton, n vertices, and Δ self-loops in O ( n ) time per tree and O ( n ) space in total. As an application, we can generate all polymer topologies with a tree skeleton, self-loops, no multiple edges, and a given cycle rank.
An interesting future research direction is to design a method that can directly count and enumerate all mutually non-isomorphic polymer topologies with a given cycle rank.

Author Contributions

Conceptualization, N.A.A. and H.N.; funding acquisition, N.A.A.; methodology, N.A.A. and H.N.; software, N.A.A.; supervision, H.N.; validation, N.A.A., A.S., and H.N.; writing, original draft, N.A.A.; writing, review and editing, N.A.A. and A.S. All authors read and agreed to the published version of the manuscript.

Funding

This research is partially funded by JSPS KAKENHI Grant Number 18J23484.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Azam, N.A.; Shurbevski, A.; Nagamochi, H. A method for enumerating pairwise compatibility graphs with a given number of vertices. In Discrete Applied Mathematics; Elsevier: Amsterdam, The Netherlands, 2020. [Google Scholar]
  2. Azam, N.A.; Shurbevski, A.; Nagamochi, H. On the Enumeration of Minimal Non-pairwise Compatibility Graphs. In Proceedings of the International Computing and Combinatorics Conference, Atlanta, GA, USA, 29–31 August 2020; Springer: New York, NY, USA, 2020; pp. 372–383. [Google Scholar]
  3. Gugisch, R.; Kerber, A.; Kohnert, A.; Laue, R.; Meringer, M.; Rücker, C.; Wassermann, A. MOLGEN 5.0, a molecular structure generator. In Advances in Mathematical Chemistry and Applications; Elsevier: Amsterdam, The Netherlands, 2015; pp. 113–138. [Google Scholar]
  4. Peironcely, J.E.; Rojas-Chertó, M.; Fichera, D.; Reijmers, T.; Coulier, L.; Faulon, J.L.; Hankemeier, T. OMG: Open molecule generator. J. Cheminf. 2012, 4, 21. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  5. Fujiwara, H.; Wang, J.; Zhao, L.; Nagamochi, H.; Akutsu, T. Enumerating treelike chemical graphs with given path frequency. J. Chem. Inf. Model. 2008, 48, 1345–1357. [Google Scholar] [CrossRef] [PubMed]
  6. Ishida, Y.; Zhao, L.; Nagamochi, H.; Akutsu, T. Improved algorithms for enumerating tree-like chemical graphs with given path frequency. Genome Inf. 2008, 21, 53–64. [Google Scholar]
  7. Suzuki, M.; Nagamochi, H.; Akutsu, T. Efficient enumeration of monocyclic chemical graphs with given path frequencies. J. Cheminf. 2014, 6, 31. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  8. Suzuki, M.; Nagamochi, H.; Akutsu, T. A 2-phase algorithm for enumerating tree-like chemical graphs satisfying given upper and lower bounds. IPSJ SIG Tech. Rep. 2012, 28, 1–8. [Google Scholar]
  9. Jin, W.; Barzilay, R.; Jaakkola, T. Junction tree variational autoencoder for molecular graph generation. arXiv 2018, arXiv:1802.04364. [Google Scholar]
  10. Nakano, S.I.; Uno, T. A Simple Constant Time Enumeration Algorithm for Free Trees; PSJ SIGNotes ALgorithms; PSJ: Tokyo, Japan, 2003. [Google Scholar]
  11. Hayat, U.; Umer, M.; Gutman, I.; Davvaz, B.; de Celis, Á.N. A novel method to construct NSSD molecular graphs. Open Math. 2019, 17, 1526–1537. [Google Scholar] [CrossRef]
  12. Blum, L.C.; Reymond, J.L. 970 million druglike small molecules for virtual screening in the chemical universe database GDB-13. J. Am. Chem. Soc. 2009, 131, 8732–8733. [Google Scholar] [CrossRef] [PubMed]
  13. Azam, N.A.; Chiewvanichakorn, R.; Zhang, F.; Shurbevski, A.; Nagamochi, H.; Akutsu, T. A method for the inverse QSAR/QSPR based on artificial neural networks and mixed integer linear programming. In Proceedings of the 13th International Joint Conference on Biomedical Engineering Systems and Technologies—Volume 3: BIOINFORMATICS, Valletta, Malta, 24–26 February 2020. [Google Scholar]
  14. Ito, R.; Azam, N.A.; Wang, C.; Shurbevski, A.; Nagamochi, H.; Akutsu, T. A Novel Method for the Inverse QSAR/QSPR to Monocyclic Chemical Compounds Based on Artificial Neural Networks and Integer Programming. In Advances in Computer Vision and Computational Biology; Research Book Series; Springer Nature: Berlin, Germany, 2020. [Google Scholar]
  15. Zhu, J.; Wang, C.; Shurbevski, A.; Nagamochi, H.; Akutsu, T. A Novel Method for Inference of Chemical Compounds of Cycle Index Two with Desired Properties Based on Artificial Neural Networks and Integer Programming. Algorithms 2020, 13, 124. [Google Scholar] [CrossRef]
  16. Méndez-Lucio, O.; Baillif, B.; Clevert, D.A.; Rouquié, D.; Wichard, J. De novo generation of hit-like molecules from gene expression signatures using artificial intelligence. Nat. Commun. 2020, 11, 1–10. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  17. Lim, J.; Hwang, S.Y.; Moon, S.; Kim, S.; Kim, W.Y. Scaffold-based molecular design with a graph generative model. Chem. Sci. 2020, 11, 1153–1164. [Google Scholar] [CrossRef] [Green Version]
  18. Meringer, M.; Schymanski, E.L. Small molecule identification with MOLGEN and mass spectrometry. Metabolites 2013, 3, 440–462. [Google Scholar] [CrossRef] [PubMed]
  19. Haruna, T.; Horiyama, T.; Shimokawa, K. On the Enumeration of Polymer Topologies; 2017-Al-162; IPSJ SIG Technical Report; Information Processing Society of Japan: Tokyo, Japan, 2017. [Google Scholar]
  20. Tezuka, Y.; Oike, H. Topological polymer chemistry. Prog. Polym. Sci. 2002, 27, 1069–1122. [Google Scholar] [CrossRef]
  21. Azam, N.A.; Shurbevski, A.; Nagamochi, H. An Efficient Algorithm to Count Tree-Like Graphs with a Given Number of Vertices and Self-Loops. Entropy 2020, 22, 923. [Google Scholar] [CrossRef]
  22. Cormen, T.H.; Leiserson, C.E.; Rivest, R.L.; Stein, C. Introduction to Algorithms; MIT Press: Cambridge, MA, USA, 2009. [Google Scholar]
  23. Masui, R.; Shurbevski, A.; Nagamochi, H. Enumeration of Unlabeled Tree by Dynamic Programming; Technica l Report No. 2019-003; Department of Applied Mathematics and Physics, Kyoto University: Kyoto, Japan, 2009; Available online: http://www.amp.i.kyoto-u.ac.jp/tecrep/ps-file/2019/2019-003.pdf (accessed on 10 October 2020).
  24. Jordan, C. Sur les assemblages de lignes. J. Reine Angew. Math. 1869, 70, 81. [Google Scholar]
Figure 1. The chemical compounds remdesivir C 27 H 35 N 6 O 8 P and dexamethasone C 22 H 29 FO 5 and their polymer topologies: (a) the chemical structure of remdesivir C 27 H 35 N 6 O 8 P taken from PubChem; (b) the chemical structure of dexamethasone C 22 H 29 FO 5 taken from PubChem; (c) the polymer topology of remdesivir with cycle rank 4; and (d) the polymer topology of dexamethasone with cycle rank 4.
Figure 1. The chemical compounds remdesivir C 27 H 35 N 6 O 8 P and dexamethasone C 22 H 29 FO 5 and their polymer topologies: (a) the chemical structure of remdesivir C 27 H 35 N 6 O 8 P taken from PubChem; (b) the chemical structure of dexamethasone C 22 H 29 FO 5 taken from PubChem; (c) the polymer topology of remdesivir with cycle rank 4; and (d) the polymer topology of dexamethasone with cycle rank 4.
Entropy 22 01295 g001
Figure 2. Three chemical compounds with their tree-like polymer topologies containing self-loops: (ac) the chemical structures of  C 12 H 22 O 11 , C 21 H 17 FO 2 , and  C 24 H 20 NP with CIDs5988, 137,321,354, 75,352, respectively, obtained from the PubChem database; (df) the polymer topologies of the chemical structures in (ac) with cycle ranks 2–4, respectively.
Figure 2. Three chemical compounds with their tree-like polymer topologies containing self-loops: (ac) the chemical structures of  C 12 H 22 O 11 , C 21 H 17 FO 2 , and  C 24 H 20 NP with CIDs5988, 137,321,354, 75,352, respectively, obtained from the PubChem database; (df) the polymer topologies of the chemical structures in (ac) with cycle ranks 2–4, respectively.
Entropy 22 01295 g002
Figure 3. Examples of an ordered tree and vertex indexing: (a) an ordered tree T = ( L , π ) with left-to-right ordering π indicated by the dashed arrow; (b) ordered tree T = ( L , π ) from (a) with vertices indexed in depth first search (DFS) order; and (c) ordered tree T = ( L , π ) from (a) with vertices indexed in sibling-depth first search (SDFS) order.
Figure 3. Examples of an ordered tree and vertex indexing: (a) an ordered tree T = ( L , π ) with left-to-right ordering π indicated by the dashed arrow; (b) ordered tree T = ( L , π ) from (a) with vertices indexed in depth first search (DFS) order; and (c) ordered tree T = ( L , π ) from (a) with vertices indexed in sibling-depth first search (SDFS) order.
Entropy 22 01295 g003
Figure 4. (a) A rooted graph H H ( 11 , 3 ) ; (b) an ordered graph K of H with left-to-right ordering π on siblings; (c) the ordered graph K of H with SDFS vertex indexing and SR ( K ) ; and (d) the canonical representation of H and the ordered graph with sequence representation equal to the canonical representation of H.
Figure 4. (a) A rooted graph H H ( 11 , 3 ) ; (b) an ordered graph K of H with left-to-right ordering π on siblings; (c) the ordered graph K of H with SDFS vertex indexing and SR ( K ) ; and (d) the canonical representation of H and the ordered graph with sequence representation equal to the canonical representation of H.
Entropy 22 01295 g004
Table 1. Experimental results of the enumeration method.
Table 1. Experimental results of the enumeration method.
( n , Δ ) # of Generated GraphsTime (s)
(5, 9)8560.278
(5, 10)11860.213
(5, 30)50,5964.354
(6, 9)42700.992
(6, 10)63331.571
(6, 30)619,431141.334
(7, 9)20,5485.084
(7, 10)32,3377.047
(8, 9)95,35717.444
(8, 10)159,05831.755
(9, 9)429,49688.899
(9, 10)756,045185.823
(10, 9)1,882,764528.286
(10, 10)3,488,567914.806
(17, 2)25,939,6793911.33
(18, 0)123,86734.189
(20, 0)823,065334.357
(22, 0)5,623,7561807.53
(24, 0)39,299,8978042.88
Table 2. The number of polymer topologies with a tree skeleton, r self-loops, and no multiple edges.
Table 2. The number of polymer topologies with a tree skeleton, r self-loops, and no multiple edges.
Rank r
n235  8   9   
111111111
211223344
3124691216
413613213551
527184077136
6162361147300
732076223559
811474288868
95542911128
102292411212
11101451057
12268733
1319390
144151
1538
166
Total24113010530815556650
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Azam, N.A.; Shurbevski, A.; Nagamochi, H. Enumerating Tree-Like Graphs and Polymer Topologies with a Given Cycle Rank. Entropy 2020, 22, 1295. https://doi.org/10.3390/e22111295

AMA Style

Azam NA, Shurbevski A, Nagamochi H. Enumerating Tree-Like Graphs and Polymer Topologies with a Given Cycle Rank. Entropy. 2020; 22(11):1295. https://doi.org/10.3390/e22111295

Chicago/Turabian Style

Azam, Naveed Ahmed, Aleksandar Shurbevski, and Hiroshi Nagamochi. 2020. "Enumerating Tree-Like Graphs and Polymer Topologies with a Given Cycle Rank" Entropy 22, no. 11: 1295. https://doi.org/10.3390/e22111295

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop