Next Article in Journal
The Spatial Regime Conversion Method
Previous Article in Journal
On the Concept of Algebraic Crystallography
Previous Article in Special Issue
Graph Theoretic Analyses of Tessellations of Five Aperiodic Polykite Unitiles
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Counting Tree-like Multigraphs with a Given Number of Vertices and Multiple Edges

Discrete Mathematics and Computational Intelligence Laboratory, Department of Mathematics, Quaid-i-Azam University, Islamabad 45320, Pakistan
*
Author to whom correspondence should be addressed.
Mathematics 2025, 13(21), 3405; https://doi.org/10.3390/math13213405
Submission received: 20 July 2025 / Revised: 18 October 2025 / Accepted: 23 October 2025 / Published: 26 October 2025
(This article belongs to the Special Issue Graph Theory and Applications, 3rd Edition)

Abstract

The enumeration of chemical graphs plays a crucial role in cheminformatics and bioinformatics, especially in the search for novel drug discovery. These graphs are usually tree-like multigraphs, or they consist of tree-like multigraphs attached to a central core. In both configurations, the tree-like components play a key role in determining the properties and activities of chemical compounds. In this work, we propose a dynamic programming approach to precisely count the number of tree-like multigraphs with a given number of n vertices and Δ multiple edges. Our method transforms multigraphs into rooted forms by designating their unicentroid or bicentroid as the root and then defining a canonical representation based on the maximal subgraphs rooted at the root’s children. This canonical form ensures that each multigraph is counted only once. Recursive formulas are then established based on the number of vertices and multiple edges in the largest subgraphs rooted at the root’s children. The resulting algorithm achieves a time complexity of O ( n 2 ( n + Δ ( n + Δ 2 · min { n , Δ } ) ) ) and space complexity of O ( n 2 ( Δ 3 + 1 ) ) . Extensive experiments demonstrate that the proposed method scales efficiently, being able to count multigraphs with up to 200 vertices (e.g., (200, 26)) and up to 50 multiple edges (e.g., (90, 50)) in under 15 min. In contrast, the available state-of-the-art tool Nauty runs out of memory beyond moderately sized instances, as it relies on explicit generation of all candidate multigraphs. These results highlight the practical advantage and strong potential of the proposed method as a scalable tool for chemical graph enumeration in drug discovery applications.
MSC:
05C30; 05C; 05A; 05C92

1. Introduction

1.1. General Context

The counting and generation of chemical compounds have a long-standing history and serve as a crucial component in applications such as novel drug discovery [1,2] and structure elucidation [3]. One way to view the challenge of counting and generating chemical compounds is to consider it as a problem of enumerating graphs under specific constraints. Enumeration with constraints has been widely studied for various applications, such as the virtual exploration of the chemical universe [4] and the reconstruction of molecular structures from their signatures [5]. Different techniques have been developed to enumerate chemical compounds [6,7]. These techniques can be categorized into two classes. The first class includes enumeration methods that focus on general graph structures [6,7]. The second class consists of techniques specifically focused on enumerating certain restricted chemical compounds [8]. A notable contribution to this area was made by Cayley [9], who laid the foundation for counting alkane isomers. The enumeration of graphs is challenging due to the rapid combinatorial explosion of possible structures. An efficient enumeration method must (i) generate all valid structures without omission, (ii) avoid duplicates by eliminating isomorphic graphs, and (iii) maintain low time and space complexity. Meeting these requirements simultaneously is difficult, particularly for graphs with multiple edges or high symmetry, where isomorphism detection and canonical representation are computationally expensive.

1.2. Motivation

Enumeration and inference of chemically meaningful graph structures under various structural and frequency-based constraints have been extensively studied in different contexts [10,11]. Chemical graph enumeration is a central problem in cheminformatics and bioinformatics, with significant importance in drug discovery. These graphs are often either tree-like multigraphs, i.e., they do not contain any rings, or consist of tree-like components connected to a central core (such as a ring). Figure 1a shows a representative example: Aspartic Acid (C4H7NO4), which lacks a ring and exhibits a tree-like molecular structure, whereas Homovanillic Acid (C9H10O4), shown in Figure 1b, includes a cyclic structure. In both cases, the tree-like portions of the structures play a critical role in determining molecular properties, reactivity, and biological function. Several studies have emphasized that acyclic functional groups, often forming tree-like multigraph structures, play a key role in molecular properties such as solubility and reactivity and are increasingly incorporated into graph-based models for chemical prediction [12,13].

1.3. Literature Review

Two major families of approaches have been widely used for graph enumeration: (i) combinatorial enumeration methods and (ii) algorithmic enumeration frameworks, particularly branch-and-bound and dynamic programming (DP). A classical technique is Pólya’s Enumeration Theorem [14,15]. The key idea is to count distinct graphs by constructing a generating function based on the cycle index of the symmetry group of the graphs. This guarantees that isomorphic graphs are counted only once. However, the computation of Pólya’s theorem depends heavily on the symmetry group of the underlying structure, and calculating the cycle index becomes computationally demanding for large or complex graphs. Branch-and-bound algorithms have been extensively studied for the enumeration of graphs, particularly for tree-like structures. MacKay and Piperno [16] developed Nauty and Traces, which employ branch-and-bound strategies to efficiently test graph isomorphism and have also been widely used for graph enumeration. Akutsu and Fukagawa [17] developed a branch-and-bound method for enumerating tree-like chemical graphs from given frequency vectors. Fujiwara et al. [18] improved this approach using the two-tree enumeration method by Nakano and Uno [19,20], showing performance comparable to the fastest existing algorithms [21]. Ishida et al. [22] presented two branch-and-bound algorithms based on path frequencies. Shimizu et al. [23] and Suzuki et al. [24] proposed feature-vector-based enumeration techniques for all tree-like (acyclic) chemical graphs. Maudet and Danoy [25] proposed a genetic-programming approach to improve branching strategies in branch-and-bound algorithms. Similarly, Sciandra et al. [26] introduced a graph convolutional branch-and-bound framework that used structural information to guide the search. Labassi et al. [27] further enhanced branch-and-bound by applying graph neural networks for adaptive node selection. Ye et al. [28] developed an efficient biclique-counting algorithm for large bipartite graphs using structural pruning techniques. Despite these advancements, branch-and-bound methods share common drawbacks: they often compute the total number of solutions only after full enumeration, generate unnecessary intermediate structures, and suffer from high computational costs. Thus, they are suitable for small or medium tree-like compounds but inefficient for large or complex chemical graphs.
Dynamic programming has emerged as a more efficient paradigm for graph enumeration, addressing many of the inefficiencies of the branch-and-bound approach. Akutsu and Fukagawa [29] introduced a DP approach for inferring graphs from path frequency, particularly providing polynomial-time solutions for bounded-degree trees and showing NP hardness for planar graphs. Further, Akutsu et al. [30] applied DP to tree-like graphs with a bounded degree, demonstrating significantly improved efficiency. Rue et al. [31] extended DP to surface-embedded graphs using surface cut decomposition, reducing the complexity to single-exponential in branchwidth, 2 O ( k ) · n . Imada et al. [32,33] developed DP approaches for enumerating stereoisomers of tree-structured molecular graphs in O ( n ) per isomer, later extending to outerplanar graphs with O ( n 3 ) complexity per isomer. Masui et al. [34] designed efficient DP algorithms for ranking, unranking, and enumerating unlabeled rooted and unrooted trees, providing a foundation for chemical tree enumeration. He et al. [35] applied DP combined with backtracking to enumerate naphthalene-containing chemical structures. DP-based enumeration using graph-theoretic feature vectors has also been explored [36] and was later extended for arbitrary chemical graphs [37,38]. Azam et al. [39] proposed a DP algorithm for counting all tree-like graphs with vertices and self-loops, and subsequently extended it to generate isomorphic tree-like multigraphs [40]. Ido et al. [41] improved efficiency further by storing paths in a DAG structure. Maristany de las Casas et al. [42] developed a DP approach for the spanning tree problem. Yanhaona et al. [43] proposed the DP algorithm for efficiently enumerating all spanning trees of a plane 3-tree.
Beyond branch-and-bound and DP paradigms, several specialized enumeration methods have been developed to address graph-specific enumeration problems. Haraguchi and Nagamochi [44] developed a family-tree traversal algorithm for polynomial-delay enumeration of connectors under various connectivity conditions. Tada and Haraguchi [45] used partitioning with minimal removable sets in set systems to achieve linear-delay enumeration of 2-edge- or 2-vertex-connected induced subgraphs. Shota and Haraguchi [46] applied the superset–subset–disjoint (SSD) system framework for efficient, linear-delay enumeration of strongly connected induced subgraphs. Sun et al. [47] presented approaches for enumerating subtrees of planar two-tree networks. Qian and Uehara [48] proposed a constant-time enumeration algorithm for weighted trees. A summary of these techniques is given in Table 1.

1.4. Contributions

In this paper, we focus on the exact enumeration of tree-like multigraphs with a given number of n vertices, Δ multiple edges, and no self-loops, using DP. For this purpose, we treat each graph as a rooted graph by designating either a unicentroid or a bicentroid as the root. Recursive relations are derived based on the maximal subgraphs attached to the roots of the underlying graphs, which form the foundation of the DP algorithm. To avoid redundant solutions, we introduce a canonical ordering for the maximal subgraphs. We analyze the theoretical time and space complexities of the proposed algorithm, which are O ( n 2 ( n + Δ ( n + Δ 2 · min { n , Δ } ) ) ) and O ( n 2 ( Δ 3 + 1 ) ) , respectively. The proposed algorithm has been implemented to count the desired multigraphs for various values of n and Δ. To the best of our knowledge, there is no existing algorithm capable of directly counting the underlying multigraphs. The graph enumeration algorithm Nauty, developed by McKay and Piperno [16], is the state of the art for enumerating simple graphs and multigraphs. To demonstrate the effectiveness of the proposed counting algorithm, the computational results are compared with those obtained using Nauty [16]. Experimental results demonstrate that the proposed method can efficiently handle instances with up to 200 vertices (e.g., (200, 26)) and up to 50 multiple edges (e.g., (90, 50)) in under 805 s. While Nauty successfully computes results for smaller instances, as the instance size increases, it quickly encounters memory exhaustion and is unable to proceed further. For example, it encounters memory exhaustion starting from n = 9 and Δ = 50 , due to its requirement to explicitly generate and store all underlying multigraphs before counting.

1.5. Organization

The structure of the paper is as follows: Preliminaries are discussed in Section 2. Section 3 discusses a recursive relation for enumerating tree-like multigraphs with a given number of vertices and multiple edges, which serves as the foundation for designing a DP-based counting algorithm. Experimental results for tree-like multigraphs are presented in Section 3.6. A conclusion with future directions is provided in Section 4.

2. Preliminaries

A graph is defined as an ordered pair G = ( V , E ) , where V represents the set of vertices and E represents the set of edges. For any graph G, we denote its vertex set and edge set by V ( G ) and E ( G ) , respectively. An edge connecting two vertices u and v is written as u v . If u and v are connected by an edge u v , they are referred to as adjacent vertices. An edge u v is said to be incident to the vertices u and v. An edge that begins and ends at the same vertex, i.e.,  u u , is called a self-loop. The multiplicity of an edge u v refers to the number of multiple edges connecting u and v, and it is denoted by e ( u v ) . For example, in Figure 2, the multiplicity of the edge v 1 v 2 is 0, since there are no multiple edges between v 1 and v 2 . Likewise, the multiplicity of the edge v 2 v 3 is 1, as there exists one additional edge between v 2 and v 3 . A graph that contains neither self-loops nor multiple edges is known as a simple graph. A graph that may include multiple edges or self-loops is called a multigraph. From here onwards, we focus exclusively on graphs that allow multiple edges but exclude self-loops.
Let M be a multigraph. An illustration of a multigraph M is shown in Figure 2. The set of vertices adjacent to a vertex v in M is called the set of neighbors of v and is denoted by N ( v ) . The degree of a vertex v in M, denoted by deg M ( v ) , is defined as the number of edges incident to v. For example, as illustrated in Figure 2, deg M ( v 2 ) = 4 . A subgraph of M is a graph H = ( V , E ) such that V V and E E . A path P ( u , v ) between vertices u and v is defined as a sequence of vertices w 1 , w 2 , , w n where w 1 = u , w n = v , and  w i w i + 1 is an edge for all i = 1 , , n 1 . A path is referred to as a simple path from u to v if no vertex appears more than once. A graph is said to be connected if a path exists between every pair of distinct vertices. A connected component of M is a maximal connected subgraph of M. For a subset X V ( M ) , the induced subgraph M [ X ] is the subgraph of M with vertex set X and an edge set consisting of all edges in E ( M ) that have both endpoints in X. A cycle is defined as a path that starts and ends at the same vertex, contains at least three vertices, and has no repeated edges or vertices except for the starting and ending vertex.
A tree-like multigraph is defined as a connected multigraph that does not contain any cycles. A tree-like multigraph with a specifically designated vertex is referred to as a rooted tree-like multigraph. Let M denote a rooted tree-like multigraph, and let r M represent the root of M. An ancestor of a vertex v V ( M ) { r M } is any vertex, other than v itself, that lies on the path P ( v , r M ) connecting v to the root r M . Vertices for which v acts as an ancestor are called the descendants of v. The parent p ( v ) of a vertex v V ( M ) { r M } is defined as the ancestor u of v such that u v E ( M ) . The vertex v is referred to as a child of p ( v ) . Vertices in a rooted tree-like multigraph that have the same parent are known as siblings. For a vertex v V ( M ) , let M v denote the descendant subgraph of M rooted at v, which is the subgraph induced by v and all of its descendants. Note that the descendant subgraph M v is a maximal rooted tree-like multigraph of M, rooted at v and induced by v together with its descendants. We denote by v ( M v ) the number of vertices and by e ( M v ) the number of multiple edges in the descendant subgraph M v . An illustration of a rooted tree-like multigraph is shown in Figure 3.
According to Jordan [49], in a tree with n vertices, there exists either a unique vertex or a unique edge such that removing it divides the tree into connected components, each containing at most ( n 1 ) / 2 vertices or exactly n / 2 vertices. This type of vertex is referred to as a unicentroid, illustrated in Figure 4a, while such an edge is called the bicentroid, as shown in Figure 4b. Collectively, they are known as the centroid. Note that a bicentroid only exists for an even number of vertices.
Two rooted tree-like multigraphs, M and N with roots r M and r N , resp., are defined as isomorphic when there exists a bijective mapping φ : V ( M ) V ( N ) between their vertex sets such that u v E ( M ) if and only if φ ( u ) φ ( v ) E ( N ) , φ ( r M ) = r N and e ( u v ) = e ( φ ( u v ) ) for any two vertices u , v V ( M ) , where e ( u v ) denotes the number of edges between u and v. An example of two isomorphic graphs is shown in Figure 5.
Let n 0 and Δ 0 be any two integers. We denote by M ( n , Δ ) the set of all mutually non-isomorphic rooted tree-like multigraphs with n vertices and Δ multiple edges. The size of M ( n , Δ ) is denoted by m ( n , Δ ) .

3. Proposed Method

We focus on counting the exact number  m ( n , Δ ) of mutually non-isomorphic rooted tree-like multigraphs with a prescribed number of vertices, multiple edges, and no self-loops. For  n = 0 , 1 and any Δ 1 , m ( n , Δ ) = 0 , and  m ( 2 , Δ ) = 1 . Figure 6a illustrates the case m ( 2 , Δ ) = 1 . Members of the family M ( 3 , 2 ) corresponding to n = 3 and Δ = 2 are shown in Figure 6b. We develop a DP algorithm to compute m ( n , Δ ) , thereby obtaining the exact number of mutually non-isomorphic tree-like multigraphs.

3.1. Canonical Representation

For an enumeration method, it is essential to avoid generating isomorphic graphs. To achieve this, we define a canonical representation for graphs in M ( n , Δ ) . This representation utilizes information about the number of vertices and multiple edges in the descendant subgraphs, as well as the number of multiple edges between the root and its children in the corresponding underlying multigraphs. Formally, the ordered representation of a multigraph M M ( n , Δ ) is defined as an ordered multigraph in which the descendant subgraphs are arranged from left to right according to the following criteria. Consider a vertex of a multigraph and the descendant subgraphs of its children. (a) First, order the descendant subgraphs in the non-increasing order of the number of vertices. (b) More than one subgraph with the same number of vertices is further ordered in the non-increasing order of the number of multiple edges. (c) Finally, the subgraphs with the same number of multiple edges are arranged in the non-increasing order of the number of multiple edges between the root of the multigraph and the roots of descendant subgraphs. We define the canonical representation of a multigraph M M ( n , Δ ) to be the ordered representation that satisfies (a)–(c) for each vertex. Henceforth, we assume that all graphs in M ( n , Δ ) are represented in their canonical form. For n = 10 and Δ = 7 , the canonical representation of a graph M is shown in Figure 7a, while the non-canonical representation of M is shown in Figure 7b.

3.2. Subproblem

We define the subproblems for DP based on the descendant subgraphs with the maximum number of vertices and multiple edges. For this purpose, we define the following terms for each M M ( n , Δ ) ,
Max v ( M ) max { { v ( M v ) : v N ( r M ) } { 0 } } , Max m ( M ) max { { e ( M v ) : v N ( r M ) , v ( M v ) = Max v ( M ) } { 0 } } , Max l ( M ) max { { e ( r M r M v ) : v ( M v ) = Max v ( M ) and e ( M v ) = Max m ( M ) } { 0 } } .
Intuitively, Max v ( M )  represents the maximum number of vertices in the descendant subgraphs. Max m ( M )  represents the maximum number of multiple edges in the descendant subgraphs with Max v ( M ) vertices. Finally, Max l ( M )  represents the maximum number of multiple edges between the root of M and the roots of the descendant subgraphs containing Max v ( M ) vertices and Max m ( M ) multiple edges. Note that for any multigraph M M ( 1 , Δ ) , it holds that Max v ( M ) = 0 , Max m ( M ) = 0 , and Max l ( M ) = 0 . For example, the multigraph in Figure 7a, Max v ( M ) = 4 , Max m ( M ) = 2 , and  Max l ( M ) = 1 .
Let k , d , l be any three integers such that k 1 and d , l 0 . We define a subproblem of M ( n , Δ ) for DP as follows:
M ( n , Δ , k , d , l ) { M M ( n , Δ ) : Max v ( M ) k , Max m ( M ) d , Max l ( M ) l } .
That is, M ( n , Δ , k , d , l ) denotes the set of mutually non-isomorphic rooted tree-like multigraphs with n vertices and Δ multiple edges, where k, d, and  are upper bounds on the maximum number Max v of vertices in the descendant subgraphs, Max m , and  Max l , respectively. Note that according to the definition of M ( n , Δ , k , d , l ) , it follows that
(i)
M ( n , Δ , k , d , l ) = M ( n , Δ , n 1 , d , l ) if k n ;
(ii)
M ( n , Δ , k , d , l ) = M ( n , Δ , k , Δ , l ) if d Δ + 1 ;
(iii)
M ( n , Δ , k , d , l ) = M ( n , Δ , k , d , Δ ) if l Δ + 1 ; and
(iv)
M ( n , Δ ) = M ( n , Δ , n 1 , Δ , Δ ) .
Consequently, we suppose that  k n 1 and  d + l Δ . Moreover, according to the definition, it holds that M ( n , Δ , k , d , l ) if n = 1 and Δ = 0 or n 1 k 1 and M ( n , Δ , k , d , l ) = if n = 1 and Δ 1 or n 2 and k = 0 .
We define the subproblems of M ( n , Δ , k , d , l ) based on the maximum number of vertices in the descendant subgraphs:
M ( n , Δ , k = , d , l ) { M M ( n , Δ , k , d , l ) : Max v ( M ) = k } .
M ( n , Δ , k = , d , l ) denotes the subset of M ( n , Δ , k , d , l ) consisting of rooted tree-like multigraphs with n vertices, Δ multiple edges, and exactly k maximum number of vertices in the descendant subgraphs. According to the definition of M ( n , Δ , k = , d , l ) that M ( n , Δ , k = , d , l ) if n = 1 and Δ = 0 or n 1 k 1 , and  M ( n , Δ , k = , d , l ) = if n = 1 and Δ 1 or n 2 and k = 0 . In addition, we have the following recursive relation:
M ( n , Δ , k , d , l ) = M ( n , Δ , 0 = , d , l ) if k = 0 ,
M ( n , Δ , k , d , l ) = M ( n , Δ , k 1 , d , l ) M ( n , Δ , k = , d , l ) if k 1 ,
where M ( n , Δ , k 1 , d , l ) M ( n , Δ , k = , d , l ) = for k 1 . This recursive relation is shown in Figure 8.
We define the subproblems of M ( n , Δ , k = , d , l ) based on the maximum number of multiple edges in the descendant subgraphs:
M ( n , Δ , k = , d = , l ) { M M ( n , Δ , k = , d , l ) : Max m ( M ) = d } .
That is, M ( n , Δ , k = , d = , l ) denotes the subset of M ( n , Δ , k = , d , l ) of rooted tree-like multigraphs such that Max m ( M ) = d . According to definition of M ( n , Δ , k = , d = , l ) , it follows that M ( n , Δ , k = , d = , l ) if n = 1 and Δ = 0 or n 1 k 1 and M ( n , Δ , k = , d = , l ) = in the case of n = 1 and Δ 1 or n 2 and k = 0 . We also obtain the following relation for M ( n , Δ , k = , d , l ) :
M ( n , Δ , k = , d , l ) = M ( n , Δ , k = , 0 = , l ) if d = 0 ,
M ( n , Δ , k = , d , l ) = M ( n , Δ , k = , d 1 , l ) M ( n , Δ , k = , d = , l ) if d 1 ,
where M ( n , Δ , k = , d 1 , l ) M ( n , Δ , k = , d = , l ) = for d 1 . This recursive relation is shown in Figure 8.
Similarly, we define the subproblems of M ( n , Δ , k = , d = , l ) based on the maximum number of multiple edges between the root and its children in the multigraphs:
M ( n , Δ , k = , d = , l = ) { M M ( n , Δ , k = , d = , l ) : Max l ( M ) = l } .
According to the definition of M ( n , Δ , k = , d = , l = ) , it follows that M ( n , Δ , k = , d = , l = ) if n = 1 and Δ = 0 or n 1 k 1 and M ( n , Δ , k = , d = , l = ) = if n = 1 and Δ 1 or n 2 and k = 0 .
We obtain the following relation for M ( n , Δ , k = , d = , l ) :
M ( n , Δ , k = , d = , l ) = M ( n , Δ , k = , d = , 0 = ) if l = 0 ,
M ( n , Δ , k = , d = , l ) = M ( n , Δ , k = , d = , l 1 ) M ( n , Δ , k = , d = , l = ) if l 1 ,
where M ( n , Δ , k = , d = , l 1 ) M ( n , Δ , k = , d = , l = ) = for l 1 . This recursive relation is shown in Figure 8.

3.3. Recursive Relations

To obtain recursive relations for computing the size of M ( n , Δ , k = , d = , l = ) , it is essential to analyze the types of descendant subgraphs. Let M be a multigraph such that M M ( n , Δ , k = , d = , l = ) . Then it is easy to observe that for any vertex v N ( r M ) , the descendant subgraph M v  meets precisely one of the following four conditions. 
(C1)
v ( M v ) = k , e ( M v ) = d and e ( r M r M v ) = l .
(C2)
v ( M v ) = k , e ( M v ) = d and 0 e ( r M r M v ) < l .
(C3)
v ( M v ) = k , 0 e ( M v ) < d and 0 e ( r M r M v ) Δ .
(C4)
v ( M v ) < k , 0 e ( M v ) Δ and 0 e ( r M r M v ) Δ .
These cases are demonstrated by an example of multigraph M M ( 20 , 15 ) in Figure 9.
We define the residual multigraph of M M ( n , Δ , k = , d = , l = ) to be the multigraph rooted at r M that is induced by the vertices V ( M ) V ( M v ) . v N ( r M ) , M v M ( k , d , k 1 , d , d ) Basically, a residual multigraph consists of the descendant subgraphs of M whose structures are not clear. The residual multigraph of M contains at least one vertex, which is the root of M. An illustration of a residual multigraph is given in Figure 10.
A characterization of the residual multigraph is discussed in Lemma 1.
Lemma 1. 
For any five integers n 3 , k 1 , Δ d + l 0 , and a multigraph M M ( n , Δ , k = , d = , l = ) let  p = | { v N ( r M ) : M v M ( k , d , k 1 , d , d ) } | . Then it holds that
(i)
1 p ( n 1 ) / k with p Δ / ( d + l ) when d + l 1 .
(ii)
The residual multigraph of M belongs to exactly one of the following families:
M ( n p k , Δ p ( d + l ) , k = , d = , min { Δ p ( d + l ) , l 1 } ) ;
M ( n p k , Δ p ( d + l ) , k = , min { Δ p ( d + l ) , d 1 } , Δ p ( d + l ) ) ; or
M ( n p k , Δ p ( d + l ) , min { n p k 1 , k 1 } , Δ p ( d + l ) , Δ p ( d + l ) ) .
Proof. 
(i)
Since M M ( n , Δ , k = , d = , l = ) , there is at least one vertex  v N ( r M ) such that M v M ( k , d , k 1 , d , d ) . It follows that p 1 . It further asserts that n 1 p k and Δ p ( d + l ) . This concludes that p ( n 1 ) / k with p Δ / ( d + l ) when d + l 1 .
(ii)
Let R represent the residual multigraph of M. By definition of R, it holds that R M ( n p k , Δ p ( d + l ) , n p k 1 , Δ p ( d + l ) , Δ p ( d + l ) ) . Moreover, for each vertex v N ( r M ) V ( R ) , the descendant subgraph M v satisfies exactly one of the Conditions  (C2)–(C4). Now, if there exists a vertex v N ( r M ) V ( R ) such that M v satisfies Condition (C2) as illustrated in Figure 11a, then l 1 0 , and hence R M ( n p k , Δ p ( d + l ) , k = , d = , min { Δ p ( d + l ) , l 1 } ) . For v N ( r M ) V ( R ) such that M v satisfies Condition (C3) as illustrated in Figure 11b, i.e.,  v ( M v ) = k , 0 e ( M v ) min { Δ p ( d + l ) , d 1 } and 0 e ( r M r M v ) Δ p ( d + l ) , then the residual multigraph R M ( n p k , Δ p ( d + l ) , k = , min { Δ p ( d + l ) , d 1 } , Δ p ( d + l ) ) . If M v satisfies Condition (C4) as illustrated in Figure 11c, i.e.,  v ( M v ) < k , 0 e ( M v ) Δ p ( d + l ) and 0 e ( r M r M v ) Δ p ( d + l ) , then by definition of R, it holds that R M ( n p k , Δ p ( d + l ) , min { n p k 1 , k 1 } , Δ p ( d + l ) , Δ p ( d + l ) ) .
Figure 11. An illustration of different kinds of residual multigraphs depicted with dashed lines: (a) a residual multigraph satisfying Condition (C2); (b) a residual multigraph satisfying Condition (C3); (c) a residual multigraph satisfying Condition (C4).
Figure 11. An illustration of different kinds of residual multigraphs depicted with dashed lines: (a) a residual multigraph satisfying Condition (C2); (b) a residual multigraph satisfying Condition (C3); (c) a residual multigraph satisfying Condition (C4).
Mathematics 13 03405 g011
Let n, k, Δ, d, and  be five non-negative integers such that n 1 k 0 and  Δ d + l 0 . Let m ( n , Δ , k , d , l ) , m ( n , Δ , k = , d , l ) , m ( n , Δ , k = , d = , l ) , and m ( n , Δ , k = , d = , l = ) represent the number of elements in the families  M ( n , Δ , k , d , l ) , M ( n , Δ , k = , d , l ) , M ( n , Δ , k = , d = , l ) , and M ( n , Δ , k = , d = , l = ) , respectively. For any six integers n 3 , k 1 , Δ d + l 0 , and x 0 , let
f ( k , d ; x ) m ( k , d , k 1 , d , d ) + x 1 x = ( m ( k , d , k 1 , d , d ) + x 1 ) ! ( m ( k , d , k 1 , d , d ) 1 ) ! x ! .
denotes the number of combinations with repetition of x descendant subgraphs from the family M ( k , d , k 1 , d , d ) . With all necessary information, we are ready to discuss a recursive relation for m ( n , Δ , k = , d = , l = ) in Lemma 2, and these relations are shown in Figure 12.
Lemma 2. 
For any six integers n 3 , k 1 , Δ d + l 0 , and p, such that 1 p ( n 1 ) / k with p Δ / ( d + l ) when d + l 1 and 0 l Δ , it holds that
(i)
m ( n , Δ , k = , d = , l = ) = p f ( k , d ; p ) ( m ( n p k , Δ , min { n p k 1 , k 1 } , Δ , Δ ) ) if d = 0 and l = 0 ;
(ii)
m ( n , Δ , k = , d = , l = ) = p f ( k , d ; p ) ( m ( n p k , Δ p d , k = , min { Δ p d , d 1 } , Δ p d ) + m ( n p k , Δ p d , min { n p k 1 , k 1 } , Δ p d , Δ p d ) ) if d 1 and l = 0 ;
(iii)
m ( n , Δ , k = , d = , l = ) = p f ( k , d ; p ) ( m ( n p k , Δ p l , k = , d = , min { Δ p l , l 1 } ) + m ( n p k , Δ p l , min { n p k 1 , k 1 } , Δ p l , Δ p l ) ) if d = 0 and l 1 ;
(iv)
m ( n , Δ , k = , d = , l = ) = p f ( k , d ; p ) ( m ( n p k , Δ p ( d + l ) , k = , d = , min { Δ p ( d + l ) , l 1 } ) + m ( n k p , Δ p ( d + l ) , k = , min { Δ p ( d + l ) , d 1 } , Δ p ( d + l ) ) + m ( n k p , Δ p ( d + l ) , min { n p k 1 , k 1 } , Δ p ( d + l ) , Δ p ( d + l ) ) ) if d 1 and l 1 .
Proof. 
Let us consider a multigraph M from the family M ( n , Δ , k = , d = , l = ) . m ( k , d , k 1 , d , d ) represents the number of multigraphs in the family M ( k , d , k 1 , d , d ) . Therefore by Lemma 1(i), for a specific value of p as 1 p ( n 1 ) / k with p Δ / ( d + l ) when d + l 1 , there are exactly p descendant subgraphs M v for v N ( r M ) and M v M ( k , d , k 1 , d , d ) . m ( k , d , k 1 , d , d ) + p 1 p denotes the number of combinations with a repetition of p trees from the family M ( k , d , k 1 , d , d ) for v N ( r M ) . Further, by Lemma 1(ii), the residual subgraph R of M belongs to exactly one of the following families,
M ( n p k , Δ , min { n p k 1 , k 1 } , Δ , Δ ) ) if d = 0 and l = 0 ; or
  • M ( n p k , Δ p d , k = , min { Δ p d , d 1 } , Δ p d ) M ( n p k , Δ p d , min { n p k 1 , k 1 } , Δ p d , Δ p d ) ) if d 1 and l = 0 ; or
  • M ( n p k , Δ p l , k = , d = , min { Δ p l , l 1 } ) M ( n p k , Δ p l , min { n p k 1 , k 1 } , Δ p l , Δ p l ) ) if d = 0 and l 1 ;
  • M ( n p k , Δ p ( d + l ) , k = , d = , min { Δ p ( d + l ) , l 1 } ) M ( n p k , Δ p ( d + l ) , k = , min { Δ p ( d + l ) , d 1 } , Δ p ( d + l ) ) M ( n p k , Δ p ( d + l ) , min { n p k 1 , k 1 } , Δ p ( d + l ) , Δ p ( d + l ) ) ) if d 1 and l 1 .
Note that in each case, the intersection of any two families of the residual trees will always result in an empty set. By the sum rule of counting, the total number of multigraphs in the families of residual multigraphs is
(a)
m ( n p k , Δ , min { n p k 1 , k 1 } , Δ , Δ ) if d = 0 and l = 0 ;
(b)
m ( n p k , Δ p d , k = , min { Δ p d , d 1 } , Δ p d ) + m ( n p k , Δ p d , min { n p k 1 , k 1 } , Δ p d , Δ p d ) if d 1 and l = 0 ;
(c)
m ( n p k , Δ p l , k = , d = , min { Δ p l , l 1 } ) + m ( n p k , Δ p l , min { n p k 1 , k 1 } , Δ p l , Δ p l ) if d = 0 and l 1 ;
(d)
m ( n p k , Δ p ( d + l ) , k = , d = , min { Δ p ( d + l ) , l 1 } ) + m ( n p k , Δ p ( d + l ) , k = , min { Δ p ( d + l ) , d 1 } , Δ p ( d + l ) ) + m ( n p k , Δ p ( d + l ) , min { n p k 1 , k 1 } , Δ p ( d + l ) , Δ p ( d + l ) ) if d 1 and l 1 .
This indicates that for any fixed integer p within the range specified in the statement, and by the product rule of counting, the number of residual multigraphs R in the family M ( n , Δ , k = , d = , l = ) with exactly p descendant subgraphs R v M ( k , d , k 1 , d , d ) , for  v M ( r R ) , are
(a)
f ( k , d ; p ) ( m ( n p k , Δ , min { n p k 1 , k 1 } , Δ , Δ ) ) if d = 0 and l = 0 ;
(b)
f ( k , d ; p ) ( m ( n p k , Δ p d , k = , min { Δ p d , d 1 } , Δ p d ) + m ( n p k , Δ p d , min { n p k 1 , k 1 } , Δ p d , Δ p d ) ) if d 1 and l = 0 ;
(c)
f ( k , d ; p ) ( m ( n p k , Δ p l , k = , d = , min { Δ p l , l 1 } ) + m ( n p k , Δ p l , min { n p k 1 , k 1 } , Δ p l , Δ p l ) ) if d = 0 and l 1 ;
(d)
f ( k , d ; p ) ( m ( n p k , Δ p ( d + l ) , k = , d = , min { Δ p ( d + l ) , l 1 } ) + m ( n p k , Δ p ( d + l ) , k = , min { Δ p ( d + l ) , d 1 } , Δ p ( d + l ) ) + m ( n p k , Δ p ( d + l ) , min { n p k 1 , k 1 } , Δ p ( d + l ) , Δ p ( d + l ) ) ) if d 1 and l 1 .
Note that in the case of n = 1 and Δ 1 , m ( 1 , Δ ) = 0 , whereas for n = 2 and Δ 1 , we have m ( 2 , Δ ) = 1 . Similarly for k = 1 and Δ = 0 , we have 1 p n 1 , then by Lemma 4(ii), it holds that m ( n p , 0 , 0 , 0 , 0 ) = 1 if p = n 1 and m ( n p , 0 , 0 , 0 , 0 ) = 0 if 1 p n 2 . This implies that any multigraph M M ( n , 0 , 1 = , 0 = , 0 = ) has exactly p = n 1 descendant subgraph M v M ( 1 , 0 , 0 , 0 , 0 ) , for  v N ( r M ) . However, it can be observed that for every integer k 2 or d + l 1 , and p satisfying the conditions given in the statement, there exists at least one multigraph M M ( n , Δ , k = , d = , l = ) such that M has exactly p descendant subgraphs M v M ( k , d , k 1 , d , d ) for  v N ( r M ) . This and cases (a)–(d) imply the statements (i)–(iv), respectively.    □
Theorem 1. 
For any six integers n 3 , k 1 , Δ d + l 0 , and p, such that 1 p ( n 1 ) / k with p Δ / ( d + l ) when d + l 1 and 0 l Δ , it holds that
(i)
m ( n , Δ , k = , d = , l = ) = p f ( k , d ; p 1 ) ( ( m ( k , d , k 1 , d , d ) + p 1 ) / p ) ( m ( n p k , Δ , min { n p k 1 , k 1 } , Δ , Δ ) ) if d = 0 and l = 0 ;
(ii)
m ( n , Δ , k = , d = , l = ) = p f ( k , d ; p 1 ) ( ( m ( k , d , k 1 , d , d ) + p 1 ) / p ) ( m ( n p k , Δ p d , k = , min { Δ p d , d 1 } , Δ p d ) + m ( n p k , Δ p d , min { n p k 1 , k 1 } , Δ p d , Δ p d ) ) if d 1 and l = 0 ;
(iii)
m ( n , Δ , k = , d = , l = ) = p f ( k , d ; p 1 ) ( ( m ( k , d , k 1 , d , d ) + p 1 ) / p ) ( m ( n p k , Δ p l , k = , d = , min { Δ p l , l 1 } ) + m ( n p k , Δ p l , min { n p k 1 , k 1 } , Δ p l , Δ p l ) ) if d = 0 and l 1 ;
(iv)
m ( n , Δ , k = , d = , l = ) = p f ( k , d ; p 1 ) ( ( m ( k , d , k 1 , d , d ) + p 1 ) / p ) ( m ( n p k , Δ p ( d + l ) , k = , d = , min { Δ p ( d + l ) , l 1 } ) + m ( n p k , Δ p ( d + l ) , k = , min { Δ p ( d + l ) , d 1 } , Δ p ( d + l ) ) + m ( n p k , Δ p ( d + l ) , min { n p k 1 , k 1 } , Δ p ( d + l ) , Δ p ( d + l ) ) ) if d 1 and l 1 .
Proof. 
The proof of Theorem 1 follows from Lemma 2. Furthermore, it holds that
f ( k , d ; p ) = ( m ( k , d , k 1 , d , d ) + p 1 ) ! ( m ( k , d , k 1 , d , d ) 1 ) ! p ! = ( m ( k , d , k 1 , d , d ) + p 2 ) ! ( m ( k , d , k 1 , d , d ) 1 ) ! ( p 1 ) ! × ( m ( k , d , k 1 , d , d ) + p 1 ) p = f ( k , d ; p 1 ) × ( m ( k , d , k 1 , d , d ) + p 1 ) p .
   □
In Lemma 3, we discuss the recursive relations for m ( n , Δ , k , d , l ) , m ( n , Δ , k = , d , l ) , and m ( n , Δ , k = , d = , l ) .
Lemma 3. 
For any five integers n 1 k 0 , and  Δ d + l 0 , it holds that
(i)
m ( n , Δ , k , d , l ) = m ( n , Δ , 0 = , d , l ) if k = 0 ;
(ii)
m ( n , Δ , k , d , l ) = m ( n , Δ , k 1 , d , l ) + m ( n , Δ , k = , d , l ) if k 1 ;
(iii)
m ( n , Δ , k = , d , l ) = m ( n , Δ , k = , 0 = , l ) if d = 0 ;
(iv)
m ( n , Δ , k = , d , l ) = m ( n , Δ , k = , d 1 , l ) + m ( n , Δ , k = , d = , l ) if d 1 ;
(v)
m ( n , Δ , k = , d = , l ) = m ( n , Δ , k = , d = , 0 = ) if l = 0 ; and
(vi)
m ( n , Δ , k = , d = , l ) = m ( n , Δ , k = , d = , l 1 ) + m ( n , Δ , k = , d = , l = ) if l 1 .
Proof. 
By Equation (1), case (i) follows. Similarly, by Equation (2), and the fact that k 1 , it holds that M ( n , Δ , k 1 , d , l ) M ( n , Δ , k = , d , l ) = , and case (ii) follows. Similarly, by Equation (3), case (iii) follows. Also by Equation (4) and the fact that for d 1 , it holds that M ( n , Δ , k = , d 1 , l ) M ( n , Δ , k = , d = , l ) = , and case (iv) follows. By Equation (5), case (v) follows. Similarly, by Equation (6) and the fact that for l 1 it follows that M ( n , Δ , k = , d = , l 1 ) M ( n , Δ , k = , d = , l = ) = , and case (vi) follows.    □

3.4. Initial Conditions

In Lemma 4, we discuss the initial conditions that are necessary to design a DP algorithm.
Lemma 4. 
For any five integers n 1 k 0 , Δ d + l 0 , it holds that
(i)
m ( n , Δ , 0 = , d = , l = ) = 1 if “ n = 1 and Δ = 0 " and m ( n , Δ , 0 , d , l ) = 0 if “ n = 1 and Δ 1 " or, “ n 2 ”;
(ii)
m ( n , Δ , 0 = , d , l ) = m ( n , Δ , 0 , d , l ) = 1 if n = 1 and Δ = 0 , and m ( n , Δ , 0 = , d , l ) = m ( n , Δ , 0 , d , l ) = 0 if n 2 ;
(iii)
m ( n , Δ , 1 = , d = , l ) = 0 if d 1 , and  m ( n , Δ , 1 = , 0 = , 0 = ) = 0 if Δ 1 ;
(iv)
m ( n , Δ , 1 = , 0 = , l = ) = m ( n , Δ , 1 = , 0 = , l ) = m ( n , Δ , 1 = , d , l ) = m ( n , Δ , 1 , d , l ) = 1 if n = 2 and l = Δ ;
(v)
m ( n , Δ , k = , d = , l = ) = 0 if d + l > Δ ; and
(vi)
m ( n , Δ , k = , d = , l = ) = m ( n , Δ , k = , d = , l ) = m ( n , Δ , k = , d , l ) = 0 if “ k n .
Proof. 
(i)
A multigraph M with max v ( M ) = 0 exists if and only if v ( M v ) = 1 , max m ( M ) = 0 , and max l ( M ) = 0 . No such tree exists with a single vertex and multiple edges.
(ii)
It follows from Lemma 3(i) and (ii) that m ( n , Δ , 0 , d , l ) = m ( n , Δ , 0 = , d , l ) .
(iii)
Since for d 1 , the size of v ( M v ) of the descendant subgraph must be at least 2 and must be in the range of 0 < l Δ .
(iv)
There is only one descendant subgraph of size 1, so the only possibility for multiple edges to be on the edges r M r M v , i.e.,  e ( r M r M v ) = l if l = Δ . In case l Δ , then there is no residual multigraph which can accommodate the remaining Δ l multiple edges.
(v)
The maximum number of multiple edges in the descendant subgraphs plus the tree-like multigraphs, i.e.,  d + l must be less than or equal to Δ . Otherwise d + l will exceed Δ as both d and have the range from 0 to Δ .
(vi)
The maximum size of the descendant subgraph can be n 1 .
As a consequence of Lemma 4, we have m ( 1 , Δ ) = 0 and m ( 2 , Δ ) = 1 for Δ 1 .

3.5. Proposed Algorithm

After deriving the recursive relations in Theorem 1 and Lemma 3 and initial conditions, we are ready to design an algorithm based on DP to compute m ( n , Δ ) with the recursive structures of m ( n , Δ , k , d , l ) , m ( n , Δ , k = , d , l ) , m ( n , Δ , k = , d = , l ) , and  m ( n , Δ , k = , d = , l = ) for 0 k n 1 and 0 d , l Δ .
Lemma 5. 
For any five integers n 1 k 0 , and  Δ d + l 0 , m ( n , Δ , k , d , l ) can be obtained in O ( n k ( n + Δ ( n + d l · min { n , Δ } ) ) ) time and O ( n k ( Δ ( d l + 1 ) + 1 ) ) space.
Proof. 
The proof of Lemma 5 follows directly from Algorithm 1 and Lemma 6.    □
Algorithm 1 An algorithm for counting m ( n , Δ , k , d , l ) based on DP
Input: 
Integers n 1 k 0 and Δ d , l 0 .
Output: 
m ( n , Δ , k , d , l ) .
  1:
m [ 1 , j , 0 = , 0 = , 0 = ] : = m [ 1 , j , 0 = , 0 = , 0 ] : = m [ 1 , j , 0 = , 0 , 0 ] : = m [ 1 , j , 0 , 0 , 0 ] : = 1 ;
  2:
m [ 2 , j , 1 = , 0 = , v = ] : = m [ 2 , j , 1 = , 0 = , j ] : = m [ 2 , j , 1 = , j , j ] : = m [ 2 , j , 1 , j , j ] : = 1 if v = j ;
  3:
m [ i , j , w = , u , v ] : = 0 if wi;
  4:
m [ 1 , j , 0 , u , v ] : = 0 if j ≥ 1;
  5:
m [ i , j , 0 = , u , v ] : = m [ i , j , 0 , u , v ] : = 0 if i ≥ 2;
  6:
m [ i , j , 1 = , u = , v ] : = 0 if u ≥ 1;
  7:
m [ i , j , w = , u = , v = ] : = 0 ; if u + v > j;
  8:
for each 2 i n , 0 j Δ , 1 w min { i , k } , 0 u min { j , d } , 0 v min { j , l } .
  9:
for  i : = 3 , , n  do
10:
    for  j : = 0 , , Δ  do
11:
        for  w : = 1 , , min { i , k }  do
12:
           for  u : = 0 , , min { j , d }  do
13:
               for  v : = 0 , , min { j , l }  do
14:
                   if  u + v j  then
15:
                       if  j = u = v = 0 and w = 1  then
16:
                           m [ i , 0 , 1 = , 0 = , 0 = ] : = m [ i , 0 , 1 = , 0 = , 0 ] : = m [ i , 0 , 1 = , 0 , 0 ] : =
                           m [ i , 0 , 1 , 0 , 0 ] : = 1
17:
                       else  w 2 or j 1 or u + v 1
18:
                           h : = 1 ; m [ i , j , w = , u = , v = ] : = 0
19:
                          if  u = v = 0  then
20:
                               z : = ( i 1 ) / w
21:
                          else  u 1 or v 1
22:
                               z : = min { ( i 1 ) / w , j / u + v }
23:
                          end if
24:
                          for  p : = 1 , 2 , , z  do
25:
                               h : = h · ( m [ w , u , w 1 , u , u ] + p 1 ) / p ;
26:
                              if  u = v = 0  then
27:
                                   m [ i , j , w = , u = , v = ] : = m [ i , j , w = , u = , v = ] + h · m [ i p w , j ,
                                  min { i p w 1 , w 1 } j , j ]
28:
                              else if  u 1 and v = 0  then
29:
                                   m [ i , j , w = , u = , v = ] : = m [ i , j , w = , u = , v = ] + h · m [ i p u ,
                                   w = , min { j p u , u 1 } , j p u ] + m [ i p w , j p u ,
                                  min { i p w 1 , w 1 } , j p u , j p u ]
30:
                              else if  u = 0 and v 1  then
31:
                                   m [ i , j , w = , u = , v = ] : = m [ i , j , w = , u = , v = ] + h · m [ i p w ,
                                   j p v , w = , u = , min { j p v , v 1 } ] + m [ i p w , j p v ,
                                  min { i p w 1 , w 1 } , j p v , j p v ]
32:
                              else if  u 1 and v 1  then
33:
                                   m [ i , j , w = , u = , v = ] : = m [ i , j , w = , u = , v = ] + h · m [ i p w ,
                                   j p ( u + v ) , w = , u = , min { j p ( u + v ) , v 1 } ] + m [ i
                                   p w , j p ( u + v ) , w = , min { j p ( u + v ) , u 1 } , j p ( u
                                   + v ) ] + m [ i p w , j p ( u + v ) , min { i p w 1 , w 1 }
                                   , j p ( u + v ) , j p ( u + v ) ]
34:
                              end if
35:
                          end for
36:
                          if  u = v = 0  then
37:
                               m [ i , j , w = , 0 , 0 ] : = m [ i , j , w = , 0 = , 0 = ]
38:
                          else if  u = 0 and v 1  then
39:
                               m [ i , j , w = , 0 , v ] : = m [ i , j , w = , 0 , v 1 ] + m [ i , j , w = , 0 = ,
                               v = ] ;
40:
                               m [ i , j , w = , u = , v ] : = m [ i , j , w = , u = , v 1 ] + m [ i , j , w = , u = ,
                               v = ]
41:
                          else if  u 1 and v = 0  then
42:
                               m [ i , j , w = , u , 0 ] : = m [ i , j , w = , u 1 , 0 ] + m [ i , j , w = , u = ,
                               0 = ] ;
43:
                               m [ i , j , w = , u = , v ] : = m [ i , j , w = , u = , 0 = ]
44:
                          else  u 1 and v 1
45:
                               m [ i , j , w = , u = , v ] : = m [ i , j , w = , u = , v 1 ] + m [ i , j , w = , u = ,
                               v = ] ;
46:
                               m [ i , j , w = , u , v ] : = m [ i , j , w = , u 1 , v ] + m [ i , j , w = , u = ,
                               v ]
47:
                          end if
48:
                           m [ i , j , w , u , v ] : = m [ i , j , w 1 , u , v ] + m [ i , j , w = , u ,
                           v ]
49:
                       end if
50:
                   else
51:
                        m [ i , j , w = , u = , v ] : = m [ i , j , w = , u = , v 1 ] + m [ i , j , w = , u = , v = ] ;
52:
                        m [ i , j , w = , u , v ] : = m [ i , j , w = , u 1 , v ] + m [ i , j , w = , u = , v ] ;
53:
                        m [ i , j , w , u , v ] : = m [ i , j , w 1 , u , v ] + m [ i , j , w = , u , v ]
54:
                   end if
55:
               end for
56:
           end for
57:
        end for
58:
    end for
59:
end for
60:
Return  m [ n , Δ , k , d , l ] as m ( n , Δ , k , d , l ) .
Corollary 1. 
For any two integers n 1 and Δ 0 , m ( n , Δ , n 1 , Δ , Δ ) can be obtained in O ( n 2 ( n + Δ ( n + Δ 2 · min { n , Δ } ) ) ) time and O ( n 2 ( Δ 3 + 1 ) ) space.
The computational complexity of the proposed algorithm depends on both the number of vertices n and the number of multiple edges Δ . As derived, the time complexity is O n 2 ( n + Δ ( n + Δ 2 · min { n , Δ } ) ) and the space complexity is O ( n 2 ( Δ 3 + 1 ) ) . When the number of multiple edges is small ( Δ < n ), the dominant terms are O ( n 3 Δ ) and O ( n 2 Δ 3 ) for time and space, respectively, indicating nearly cubic growth in n with moderate dependence on Δ . However, when Δ becomes large ( Δ n ), the multiplicity terms dominate, and the complexities rise to O ( n 3 Δ 3 ) in time and O ( n 2 Δ 3 ) in space. This analysis shows that the algorithm is computationally efficient for graphs with a small-to-moderate number of multiple edges, but its cost grows rapidly as the multiplicity increases, which is consistent with the inherent combinatorial nature of multigraph enumeration.
For any five integers satisfying n 1 k 0 and Δ d + l 0 , we design Algorithm 1 to compute m ( n , Δ , k , d , l ) . In this algorithm, for each integer 1 i n , 0 j Δ , 0 w min { i , k } , 0 u min { j , d } , and  0 v min { j , l } , the variables m i , j , w , u , v , m i , j , w = , u , v , m i , j , w = , u = , v , and  m i , j , w = , u = , v = store the values of m ( i , j , w , u , v ) , m ( i , j , w = , u , v ) , m ( i , j , w = , u = , v ) , and  m ( i , j , w = , u = , v = ) , respectively.
Lemma 6. 
For any five integers n 1 k 0 , and  Δ d + l 0 , Algorithm 1 outputs m ( n , Δ , k , d , l ) in O ( n k ( n + Δ ( n + d l · min { n , Δ } ) ) ) time and O ( n k ( Δ ( d l + 1 ) + 1 ) ) space.
Proof. 
Correctness: For each integer 1 i n , 0 j Δ , 0 w min { i , k } , 0 u min { j , d } , and  0 v min { j , l } all the substitutions and if-conditions in Algorithm 1 follow from Theorem 1 and Lemmas 1, 3, and 4. Furthermore, the values m [ i , j , w , u , v ] , m [ i , j , w = , u , v ] , m [ i , j , w = , u = , v ] , and  m [ i , j , w = , u = , v = ] are computed by the recursive relations given in Theorem 1 and Lemma 3. This implies that Algorithm 1 correctly computes the required value m [ n , Δ , k , d , l ] .
Complexity analysis: There are five nested loops over the variables i , j , w , u , and v at line 8, which take O ( n ( Δ ( k d l + k + 1 ) + k + 1 ) ) time. The following are six nested loops: over variables i , j , w , u , v , and p at lines 9, 10, 11, 12, 13, and 24, respectively. The loop at line 9 is of size O ( n ) , while the loop at line 10 is of size O ( Δ ) . Similarly, the loops at lines 11, 12, and 13 are of size O ( k ) , O ( d ) , and  O ( l ) , respectively. The six nested loops at line 24 are of size O ( n ) (resp., O ( min { n , Δ } ) if u = v = 0 (resp., otherwise). Thus, from line 9–59, Algorithm 1 takes O ( n 2 k ) (resp., O ( n k Δ ( n + d l · min { n , Δ } ) ) ) time if Δ = 0 (resp., otherwise). Therefore, Algorithm 1 takes O ( n k ( n + Δ ( n + d l · min { n , Δ } ) ) ) time.
The algorithm stores four five-dimensional arrays. When Δ = 0 , for each integer 1 i n , and  1 w min { i , k } , we store m [ i , 0 , k , 0 , 0 ] , m [ i , 0 , k = , 0 , 0 ] , m [ i , 0 , k = , 0 = , 0 ] , and m [ i , 0 , k = , 0 = , 0 = ] , taking O ( n k ) space. When Δ 1 , then for each integer 1 i n , 0 j Δ , 1 w min { i , k } , 0 u min { j , d } , and  0 v min { j , l } we store m [ i , j , w , u , v ] , m [ i , j , w = , u , v ] , m [ i , j , w = , u = , v ] , and  m [ i , j , w = , u = , v = ] taking O ( n k Δ ( d l + 1 ) ) space. Hence, Algorithm 1 takes O ( n k ( Δ ( d l + 1 ) + 1 ) ) space.    □
Theorem 2. 
For any two integers n 1 and Δ 0 , the number of non-isomorphic tree-like multigraphs with n vertices and Δ multiple edges can be obtained in O ( n 2 ( n + Δ ( n + Δ 2 · min { n , Δ } ) ) ) time and O ( n 2 ( Δ 3 + 1 ) ) space.
Proof. 
Each multigraph can be represented as a tree after removing multiple edges. According to Jordan’s result [49], every tree has either a unicentroid or a bicentroid. In the case of a unicentroid, the size of the descendant subgraph cannot exceed n / 2 , as shown in Figure 13a. The bicentroid case holds when the number of vertices is even, resulting in a multigraph with exactly two descendant subgraphs of size n / 2 , as shown in Figure 13b,c. Therefore, tree-like multigraphs can be uniquely viewed as rooted tree-like multigraphs by considering centroids as canonical roots. Thus, for odd n, it follows that the number of mutually non-isomorphic tree-like multigraphs with n vertices and Δ multiple edges is m n , Δ , n 1 2 , Δ , Δ .
Let n be an even integer. Then any tree M with n vertices, Δ multiple edges, and a bicentroid has two components, X and Y, obtained by the removal of the bicentroid such that X M ( n / 2 , i , n / 2 1 , i , i ) and Y M ( n / 2 , Δ i l , n / 2 1 , Δ i l , Δ i l ) for some 0 i Δ / 2 , where if Δ is even and l = 0 then for i = Δ / 2 , both of the components X and Y belong to M ( n / 2 , Δ / 2 , n / 2 1 , Δ / 2 , Δ / 2 ) . Note that for any 0 i ( Δ l ) / 2 , it holds that
M ( n / 2 , i , n / 2 1 , i , i ) M ( n / 2 , Δ i l , n / 2 1 , Δ i l , Δ i l ) = .
Therefore, when Δ is odd, the number of mutually non-isomorphic trees with n vertices, Δ multiple edges, and a bicentroid is
i = 0 ( Δ l ) / 2 l = 1 Δ m ( n / 2 , i , n / 2 1 , i , i ) m ( n / 2 , Δ i l , n / 2 1 , Δ i l , Δ i l ) .
For odd Δ , the representation of the bicentroid is given in Figure 13b.
When Δ is even, the number of mutually non-isomorphic trees with n vertices, Δ multiple edges, and a bicentroid is
i = 0 ( Δ 1 ) / 2 m ( n / 2 , i , n / 2 1 , i , i ) m ( n / 2 , Δ i , n / 2 1 , Δ i , Δ i ) +
i = 0 ( Δ l ) / 2 l = 1 Δ m ( n / 2 , i , n / 2 1 , i , i ) m ( n / 2 , Δ i l , n / 2 1 , Δ i l , Δ i l ) +
m ( n / 2 , Δ / 2 , n / 2 1 , Δ / 2 , Δ / 2 ) + 1 2 .
For even Δ , the representation of the bicentroid is given in Figure 13c.
Thus, when n is even and  Δ is odd, the number of mutually non-isomorphic trees with n vertices and Δ multiple edges is
m ( n , Δ , ( n 1 ) / 2 , Δ , Δ ) +
i = 0 ( Δ l ) / 2 l = 1 Δ m ( n / 2 , i , n / 2 1 , i , i ) m ( n / 2 , Δ i l , n / 2 1 , Δ i l , Δ i l ) .
When n is even and  Δ is even, the number of mutually non-isomorphic trees with n vertices and Δ multiple edges is
    m ( n , Δ , ( n 1 ) / 2 , Δ , Δ ) +
i = 0 ( Δ 1 ) / 2 m ( n / 2 , i , n / 2 1 , i , i ) m ( n / 2 , Δ i , n / 2 1 , Δ i , Δ i ) +
i = 0 ( Δ l ) / 2 l = 1 Δ m ( n / 2 , i , n / 2 1 , i , i ) m ( n / 2 , Δ i l , n / 2 1 , Δ i l , Δ i l ) +
m ( n / 2 , Δ / 2 , n / 2 1 , Δ / 2 , Δ / 2 ) + 1 2 .
   □

3.6. Experimental Results and Comparison

To assess the scalability and efficiency of the proposed algorithm, we conducted experiments to count the exact number of tree-like multigraphs with up to 200 vertices (n) and up to 50 multiple edges ( Δ ). To the best of our knowledge, there does not exist an algorithm that can directly count such tree-like multigraphs. However, to demonstrate the effectiveness of the proposed algorithm, we compared the computational results with those obtained using the state-of-the-art graph enumeration algorithm Nauty [16]. All experiments were performed on a standard computing environment equipped with a 12th Gen Intel Core i7 processor (1.7 GHz) and 16 GB of RAM. For each ( n , Δ ) pair, the experiment was repeated three times, and the runtimes were averaged.
We computed the number of multigraphs for each pair ( n , Δ ) with n = 10 , 20 , , 70 and Δ = 1 , 2 , , 50 . The computation time for the pairs ( n , Δ ) , where n = 10 , 20 , , 70 and Δ = 1 , 50 , as well as the standard deviation (SD) of the computation time for the pairs ( n , Δ ) with fixed n and Δ = 1 , 2 , , 50 , are shown in Figure 14a. At smaller instance sizes (e.g., n = 10 ), the computation completes almost instantly, with the times for ( 10 , 1 ) and ( 10 , 50 ) being approximately 0.001  s and below 6 s, respectively. Even as n increases, the proposed algorithm maintains a reasonable runtime; for example, at  n = 70 , the time for ( 70 , 50 ) remains under 340 s, while the standard deviation, around 100 s, indicates stable performance across repeated runs. The number of multigraphs counted by the proposed algorithm for the pairs ( n , Δ ) , where n = 10 , 20 , , 70 and Δ = 1 , 50 , as well as the SD of the count for the pairs ( n , Δ ) with fixed n and Δ = 1 , 2 , , 50 , are illustrated in Figure 14b. The number of tree-like multigraphs generated by the proposed algorithm grows exponentially with both n and Δ . For example, when Δ increases from 1 to 50, the count rises from 622 to 5.67 × 10 10 for n = 10 and from 6.54 × 10 29 to 1.39 × 10 60 for n = 70 . The SD also increases sharply—from 1.36 × 10 10 at n = 10 to 2.14 × 10 59 at n = 70 —indicating greater variation in the number of generated graphs as the graph size increases. These results demonstrate that the algorithm scales efficiently with problem size and handles larger instances without an excessive computational cost.
For larger instances with n 80 , the details of the experimental results are presented in Table 2. As the instance size increases, the number of tree-like multigraphs exhibits exponential growth—from 3.73 × 10 44 for ( 80 , 10 ) to more than 10 120 for ( 200 , 26 ) . Despite this rapid combinatorial escalation, the proposed algorithm successfully processed very large instances and produced exact enumeration results within practical execution times. For example, it enumerated 2.14 × 10 73 tree-like multigraphs for ( 90 , 50 ) in approximately 805 s and 1.62 × 10 120 multigraphs for ( 200 , 26 ) in 636 s. These outcomes demonstrate the robustness and computational efficiency of the dynamic programming formulation, which systematically exploits subproblem reuse to mitigate the exponential complexity inherent in multigraph enumeration. A few pairs (e.g., ( 90 , 51 ) , ( 100 , 44 ) , and  ( 200 , 27 ) ) resulted in memory out. However, overall, the results confirm that the proposed algorithm maintains excellent scalability and practical runtime behavior, even for very large problem instances. As observed from Table 2, for a fixed value of n, the running time increases more rapidly when Δ is varied from 10 to 50. In contrast, for a fixed Δ , the change in running time across different values of n with a step size of 10 is relatively small. These observations are consistent with the theoretical intuition, as the proposed algorithm involves three nested loops over Δ and two nested loops over n.
The results of the proposed DP algorithm and Nauty [16] for smaller instances with 5 n 14 are presented in Table 3. The comparison clearly demonstrates the superior performance and scalability of the proposed approach. For small multigraphs (e.g., n 7 ), both methods complete within a short time; however, as either n or Δ increases, Nauty’s runtime grows rapidly due to its reliance on exhaustive graph isomorphism checks. In contrast, the proposed DP formulation systematically reuses subproblem results and avoids redundant isomorphism testing, resulting in a significantly slower growth in execution time. For example, at  ( n , Δ ) = ( 9 , 30 ) , Nauty requires approximately 206 s, whereas the proposed algorithm completes in just over one second. The advantage becomes even more significant for larger configurations: at ( n , Δ ) = ( 9 , 50 ) , Nauty runs out of memory, while the proposed method successfully finishes within six seconds. This performance gap widens further as n increases—Nauty fails for several instances with n 10 and Δ 30 , whereas our algorithm continues to provide results efficiently. Experimental results in Table 3 empirically validate the correctness of the proposed method.

4. Conclusions

In this work, we proposed a dynamic programming algorithm to count the exact number of mutually distinct tree-like multigraphs with n vertices and Δ multiple edges for n 1 and Δ 0 . To eliminate isomorphic duplicates, we defined a specific canonical ordering, derived recursive relations, and established appropriate initial conditions. These formed the foundation of an efficient and scalable dynamic programming approach. The algorithm was implemented and experimentally evaluated on a wide range of instances. The results demonstrated high computational efficiency and scalability, even for instances with extremely large output sizes. Compared to the widely used general-purpose graph enumeration tool Nauty, our algorithm not only achieved significantly faster runtimes but also handled much larger instances that Nauty could not process due to memory limitations. These findings highlight the strength of our method in large-scale enumeration tasks, particularly in applications such as chemical graph analysis and drug discovery. A natural direction for future research is to extend the proposed algorithm to enumerate tree-like multigraphs with additional constraints, such as a prescribed degree bound for each vertex. Another interesting extension is to include self-loops in the enumeration process while still avoiding isomorphic redundancies. Furthermore, developing efficient algorithms for directly generating representative tree-like multigraphs rather than just counting them based on the canonical forms introduced in this study would be highly valuable for practical applications.

Author Contributions

Conceptualization, M.I., S.H. and N.A.A.; methodology, M.I. and N.A.A.; software, M.I. and S.H.; validation, N.A.A.; formal analysis, M.I. and N.A.A.; investigation, S.H.; data curation, M.I., S.H. and N.A.A.; writing—original draft preparation, M.I., S.H. and N.A.A.; writing—review and editing, S.H. and N.A.A.; supervision, N.A.A.; project administration, N.A.A. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

The original contributions presented in this study are included in the article. Further inquiries can be directed to the corresponding author.

Acknowledgments

The authors sincerely thank the anonymous reviewers for their valuable feedback and insightful recommendations, which helped improve both the clarity and quality of this manuscript.

Conflicts of Interest

The authors declare no conflicts of interest.

Abbreviations

The following abbreviations are used in this manuscript:
DPDynamic Programming
CIDCompound identifier
RAMRandom Access Memory

Notation

The following symbols and variables are used in this manuscript:
SymbolDescription
nNumber of vertices
Δ Number of multiple edges
MRooted tree-like multigraph
M ( n , Δ ) Set of all mutually non-isomorphic rooted tree-like multigraphs with n vertices and Δ multiple edges
m ( n , Δ ) Number of non-isomorphic rooted tree-like multigraphs with n vertices and Δ multiple edges
v ( M v ) Number of vertices in the descendent subgraphs
e ( M v ) Number of edges in the descendent subgraphs
e ( r M r M v ) Number of edges between the roots of M and root of descendent subgraphs
M a x v ( M ) Maximum number of vertices in a descendant subgraph of M
M a x m ( M ) Maximum number of multiple edges in a descendant subgraph of M
M a x l ( M ) Maximum number of multiple edges between the root of M and roots of descendant subgraph
M ( n , Δ , k , d , l ) Set of non-isomorphic rooted tree-like multigraphs with n vertices and maximum degree Δ , where any descendant subgraph has at most k vertices, at most d multiple edges, and there are at most multiple edges between the root and roots of descendant subgraphs
M ( n , Δ , k = , d , l ) Subset of M ( n , Δ , k , d , l ) where Max v ( M ) = k
M ( n , Δ , k = , d = , l ) Subset of M ( n , Δ , k = , d , l ) where Max m ( M ) = d
M ( n , Δ , k = , d = , l = ) Subset M ( n , Δ , k = , d = , l ) where Max l ( M ) = l
f ( k , d ; x ) Number of combinations with repetition of x descendant subgraphs from the family M ( k , d , k 1 , d , d )

References

  1. 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]
  2. 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]
  3. Meringer, M.; Schymanski, E.L. Small Molecule Identification with MOLGEN and Mass Spectrometry. Metabolites 2013, 3, 440–462. [Google Scholar] [CrossRef]
  4. Fink, T.; Reymond, J.-L. Virtual Exploration of the Chemical Universe up to 11 Atoms of C, N, O, F: Assembly of 26.4 Million Structures (110.9 Million Stereoisomers) and Analysis for New Ring Systems, Stereochemistry, Physicochemical Properties, Compound Classes, and Drug Discovery. J. Chem. Inf. Model. 2007, 47, 342–353. [Google Scholar] [CrossRef]
  5. Faulon, J.-L.; Churchwell, C.J.; Visco, D.P. The Signature Molecular Descriptor. 2. Enumerating Molecules from Their Extended Valence Sequences. J. Chem. Inf. Comput. Sci. 2003, 43, 721–734. [Google Scholar] [CrossRef]
  6. Benecke, C.; Grund, R.; Hohberger, R.; Kerber, A.; Laue, R.; Wieland, T. MOLGEN+, a Generator of Connectivity Isomers and Stereoisomers for Molecular Structure Elucidation. Anal. Chim. Acta 1995, 314, 141–147. [Google Scholar] [CrossRef]
  7. Peironcely, J.E.; Rojas-Chertó, M.; Fichera, D.; Reijmers, T.; Coulier, L.; Faulon, J.-L.; Hankemeier, T. OMG: Open Molecule Generator. J. Cheminform. 2012, 4, 21. [Google Scholar] [CrossRef] [PubMed]
  8. Akutsu, T.; Nagamochi, H. Comparison and Enumeration of Chemical Graphs. Comput. Struct. Biotechnol. J. 2013, 5, e201302004. [Google Scholar] [CrossRef] [PubMed]
  9. Cayley, A. On the Analytical Forms Called Trees: With Application to the Theory of Chemical Combinations; Cambridge University Press: Cambridge, UK, 1875. [Google Scholar] [CrossRef]
  10. Tamura, Y.; Nishiyama, Y.; Wang, C.; Sun, Y.; Shurbevski, A.; Nagamochi, H.; Akutsu, T. Enumerating Chemical Graphs with Mono-block 2-Augmented Tree Structure from Given Upper and Lower Bounds on Path Frequencies. arXiv 2020, arXiv:2004.06367. [Google Scholar] [CrossRef]
  11. Zhang, F.; Zhu, J.; Chiewvanichakorn, R.; Shurbevski, A.; Nagamochi, H.; Akutsu, T. A New Approach to the Design of Acyclic Chemical Compounds Using Skeleton Trees and Integer Linear Programming. Appl. Intell. 2022, 52, 17058–17072. [Google Scholar] [CrossRef]
  12. Batool, M.; Azam, N.A.; Khan, M. A Unified Approach to Inferring Chemical Compounds with the Desired Aqueous Solubility. J. Cheminform. 2024, 16, 66. [Google Scholar] [CrossRef]
  13. Cao, P.-Y.; He, Y.; Cui, M.-Y.; Zhang, X.-M.; Zhang, Q.; Zhang, H.-Y. Group Graph: A Molecular Graph Representation with Enhanced Performance, Efficiency and Interpretability. J. Cheminform. 2024, 16, 133. [Google Scholar] [CrossRef]
  14. Pólya, G.; Read, R.C. Combinatorial Enumeration of Groups, Graphs, and Chemical Compounds; Springer Science & Business Media: New York, NY, USA, 2012. [Google Scholar] [CrossRef]
  15. Pólya, G. Kombinatorische Anzahlbestimmungen für Gruppen, Graphen und chemische Verbindungen. Acta Math. 1937, 68, 145–254. [Google Scholar] [CrossRef]
  16. McKay, B.D.; Piperno, A. Practical Graph Isomorphism, II. J. Symb. Comput. 2014, 60, 94–112. [Google Scholar] [CrossRef]
  17. Akutsu, T.; Fukagawa, D. Inferring a Chemical Structure from a Feature Vector Based on Frequency of Labeled Paths and Small Fragments. In Proceedings of the 5th Asia-Pacific Bioinformatics Conference, Hong Kong, 15–17 January 2007; pp. 165–174. [Google Scholar] [CrossRef]
  18. Fujiwara, H.; Wang, J.; Zhao, L.; Nagamochi, H.; Akutsu, T. Enumerating Tree-Like Chemical Graphs with Given Path Frequency. J. Chem. Inf. Model. 2008, 48, 1345–1357. [Google Scholar] [CrossRef]
  19. Nakano, S.; Uno, T. Efficient Generation of Rooted Trees. Natl. Inst. Inform. Tech. Rep. NII-2003 2003, 8, 4–63. [Google Scholar]
  20. Nakano, S.; Uno, T. Generating Colored Trees. In Graph-Theoretic Concepts in Computer Science, Proceedings of the 31st International Workshop, WG 2005, Metz, France, 23–25 June 2005; Revised Selected Papers; Springer: Berlin/Heidelberg, Germany, 2005; pp. 249–260. [Google Scholar] [CrossRef]
  21. Aringhieri, R.; Hansen, P.; Malucelli, F. Chemical Trees Enumeration Algorithms. Q. J. Belg. Fr. Ital. Oper. Res. Soc. 2003, 1, 67–83. [Google Scholar] [CrossRef]
  22. Ishida, Y.; Zhao, L.; Nagamochi, H.; Akutsu, T. Improved Algorithms for Enumerating Tree-Like Chemical Graphs with Given Path Frequency. Genome Inform. 2008, 21, 53–64. [Google Scholar] [CrossRef] [PubMed]
  23. Shimizu, M.; Nagamochi, H.; Akutsu, T. Enumerating Tree-Like Chemical Graphs with Given Upper and Lower Bounds on Path Frequencies. BMC Bioinform. 2011, 12, S3. [Google Scholar] [CrossRef] [PubMed]
  24. 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]
  25. Maudet, G.; Danoy, G. Search Strategy Generation for Branch and Bound Using Genetic Programming. arXiv 2024, arXiv:2412.09444. [Google Scholar] [CrossRef]
  26. Sciandra, L.; Esposito, R.; Grosso, A.C.; Sacerdote, L.; Zucca, C. Graph Convolutional Branch and Bound. arXiv 2024, arXiv:2406.03099. [Google Scholar] [CrossRef]
  27. Labassi, A.G.; Chételat, D.; Lodi, A. Learning to Compare Nodes in Branch and Bound with Graph Neural Networks. arXiv 2024, arXiv:2210.16934. [Google Scholar]
  28. Ye, X.; Li, R.-H.; Dai, Q.; Qin, H.; Wang, G. Efficient Biclique Counting in Large Bipartite Graphs. Proc. ACM Manag. Data 2023, 1, 78. [Google Scholar] [CrossRef]
  29. Akutsu, T.; Fukagawa, D. Inferring a Graph from Path Frequency. In Proceedings of the 16th Annual Symposium on Combinatorial Pattern Matching (CPM), Jeju Island, Republic of Korea, 19–22 June 2005; pp. 371–382. [Google Scholar] [CrossRef]
  30. Akutsu, T.; Fukagawa, D.; Jansson, J.; Sadakane, K. Inferring a Graph from Path Frequency. Discret. Appl. Math. 2012, 160, 1416–1428. [Google Scholar] [CrossRef]
  31. Rué, J.; Sau, I.; Thilikos, D.M. Dynamic Programming for Graphs on Surfaces. ACM Trans. Algorithms 2014, 10, 8. [Google Scholar] [CrossRef]
  32. Imada, T.; Ota, S.; Nagamochi, H.; Akutsu, T. Efficient Enumeration of Stereoisomers of Tree Structured Molecules Using Dynamic Programming. J. Math. Chem. 2011, 49, 910–970. [Google Scholar] [CrossRef]
  33. Imada, T.; Ota, S.; Nagamochi, H.; Akutsu, T. Efficient Enumeration of Stereoisomers of Outerplanar Chemical Graphs Using Dynamic Programming. J. Chem. Inf. Model. 2010, 50, 1667–1679. [Google Scholar] [CrossRef]
  34. Masui, R.; Shurbevski, A.; Nagamochi, H. Enumeration of Unlabeled Tree by Dynamic Programming; Technical Report; Kyoto University: Kyoto, Japan, 2009. [Google Scholar]
  35. He, F.; Hanai, A.; Nagamochi, H.; Akutsu, T. Enumerating Naphthalene Isomers of Tree-Like Chemical Graphs. In Proceedings of the 9th International Conference on Bioinformatics Models, Methods and Algorithms (BIOSTEC 2016), Rome, Italy, 21–23 February 2016; Volume 3: BIOINFORMATICS, pp. 258–265. [Google Scholar] [CrossRef]
  36. Azam, N.A.; Zhu, J.; Sun, Y.; Shi, Y.; Shurbevski, A.; Zhao, L.; Nagamochi, H.; Akutsu, T. A novel method for inference of acyclic chemical compounds with bounded branch-height based on artificial neural networks and integer programming. Algorithms Mol. Biol. 2021, 16, 18. [Google Scholar] [CrossRef] [PubMed]
  37. Azam, N.A.; Zhu, J.; Ido, R.; Nagamochi, H.; Akutsu, T. Experimental Results of a Dynamic Programming Algorithm for Generating Chemical Isomers Based on Frequency Vectors. In Proceedings of the Fourth International Workshop on Enumeration Problems and Applications (WEPA), Online, 7–10 December 2020; p. 15. [Google Scholar]
  38. Akutsu, T.; Nagamochi, H. A Novel Method for Inference of Chemical Compounds with Prescribed Topological Substructures Based on Integer Programming. arXiv 2020, arXiv:2010.09203. [Google Scholar] [CrossRef]
  39. 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]
  40. Azam, N.A.; Shurbevski, A.; Nagamochi, H. Enumeration of Tree-Like Graphs with a Given Cycle Rank Using Dynamic Programming. Entropy 2020, 22, 1295. [Google Scholar] [CrossRef]
  41. Ido, S.; Azam, N.A.; Akutsu, T. A Dynamic Programming Algorithm for Generating Chemical Isomers Based on Frequency Vectors. Sci. Rep. 2025, 15, 9576. [Google Scholar] [CrossRef]
  42. Maristany de las Casas, P.; Sedeño-Noda, A.; Borndörfer, R. New Dynamic Programming Algorithm for the Multiobjective Minimum Spanning Tree Problem. arXiv 2023, arXiv:2306.16203. [Google Scholar] [CrossRef]
  43. Yanhaona, M.N.; Nomaan, A.S.; Rahman, M.S. Efficiently Enumerating All Spanning Trees of a Plane 3-Tree. In Graph-Theoretic Concepts in Computer Science; Springer: Cham, Switzerland, 2023. [Google Scholar] [CrossRef]
  44. Haraguchi, K.; Nagamochi, H. A Polynomial-Delay Algorithm for Enumerating Connectors Under Various Connectivity Conditions. Leibniz Int. Proc. Inform. (LIPIcs) ISAAC 2019, 149, 3. [Google Scholar] [CrossRef]
  45. Tada, T.; Haraguchi, K. A Linear Delay Algorithm for Enumeration of 2-Edge/Vertex-Connected Induced Subgraphs. arXiv 2023, arXiv:2302.05526. [Google Scholar]
  46. Shota, K.; Haraguchi, K. A Linear Delay Algorithm of Enumerating Strongly-Connected Induced Subgraphs Based on SSD Set System. In Combinatorial Algorithms. IWOCA 2025; Fernau, H., Zhu, B., Eds.; Lecture Notes in Computer Science; Springer: Cham, Switzerland, 2025; Volume 15885. [Google Scholar] [CrossRef]
  47. Sun, D.; Li, L.; Liu, K.; Wang, H.; Yang, Y. Enumeration of Subtrees of Planar Two-Tree Networks. Appl. Math. Comput. 2022, 434, 127404. [Google Scholar] [CrossRef]
  48. Qian, M.; Uehara, R. Constant Time Enumeration of Weighted Trees. Discret. Appl. Math. 2025, 375, 129–138. [Google Scholar] [CrossRef]
  49. Jordan, C. Sur les Assemblages de Lignes. J. Reine Angew. Math. 1869, 70, 185–190. [Google Scholar] [CrossRef]
Figure 1. Chemical structures of compounds from the PubChem database: (a) Aspartic Acid C4H7NO4, a tree-like multigraph, PubChem CID: 5960; (b) Homovanillic Acid C9H10O4, which includes a ring structure, PubChem CID: 1738.
Figure 1. Chemical structures of compounds from the PubChem database: (a) Aspartic Acid C4H7NO4, a tree-like multigraph, PubChem CID: 5960; (b) Homovanillic Acid C9H10O4, which includes a ring structure, PubChem CID: 1738.
Mathematics 13 03405 g001
Figure 2. Illustration of a multigraph which is a 2D graphical structure of Homovanillic Acid shown in Figure 1b.
Figure 2. Illustration of a multigraph which is a 2D graphical structure of Homovanillic Acid shown in Figure 1b.
Mathematics 13 03405 g002
Figure 3. Rooted tree-like multigraph: (a) 2D graphical structure of Aspartic Acid shown in Figure 1a; (b) the multigraph with a specified root r. For vertex v 3 , v 4 is its parent, v 1 and v 2 are its children. Vertex v 3 has no sibling, while v 4 and r are its ancestors, and v 1 and v 2 are its descendants.
Figure 3. Rooted tree-like multigraph: (a) 2D graphical structure of Aspartic Acid shown in Figure 1a; (b) the multigraph with a specified root r. For vertex v 3 , v 4 is its parent, v 1 and v 2 are its children. Vertex v 3 has no sibling, while v 4 and r are its ancestors, and v 1 and v 2 are its descendants.
Mathematics 13 03405 g003
Figure 4. (a) Unicentroid v 0 in T 1 and v 1 in T 2 ; (b) bicentroid edge formed by vertex v 1 and v 2 in T 3 .
Figure 4. (a) Unicentroid v 0 in T 1 and v 1 in T 2 ; (b) bicentroid edge formed by vertex v 1 and v 2 in T 3 .
Mathematics 13 03405 g004
Figure 5. Illustration of rooted tree-like multigraphs M and N, which are isomorphic due to the mapping of φ such that φ ( r M ) = r N , φ ( v 1 ) = v 3 , φ ( v 2 ) = v 1 , φ ( v 3 ) = v 2 , φ ( v 4 ) = v 7 , φ ( v 5 ) = v 8 , φ ( v 6 ) = v 4 , φ ( v 7 ) = v 6 , and φ ( v 8 ) = v 5 .
Figure 5. Illustration of rooted tree-like multigraphs M and N, which are isomorphic due to the mapping of φ such that φ ( r M ) = r N , φ ( v 1 ) = v 3 , φ ( v 2 ) = v 1 , φ ( v 3 ) = v 2 , φ ( v 4 ) = v 7 , φ ( v 5 ) = v 8 , φ ( v 6 ) = v 4 , φ ( v 7 ) = v 6 , and φ ( v 8 ) = v 5 .
Mathematics 13 03405 g005
Figure 6. (a) Illustration of the unique graph corresponding to m ( 2 , Δ ) = 1 for n = 2 and Δ 1 ; (b) examples of graphs of the family M ( 3 , 2 ) .
Figure 6. (a) Illustration of the unique graph corresponding to m ( 2 , Δ ) = 1 for n = 2 and Δ 1 ; (b) examples of graphs of the family M ( 3 , 2 ) .
Mathematics 13 03405 g006
Figure 7. Representations of a graph M with 10 vertices and 7 multiple edges: (a) canonical representation of M; (b) non-canonical representation of M.
Figure 7. Representations of a graph M with 10 vertices and 7 multiple edges: (a) canonical representation of M; (b) non-canonical representation of M.
Mathematics 13 03405 g007
Figure 8. Illustration of the recursive relations as discussed in Equations (1)–(6).
Figure 8. Illustration of the recursive relations as discussed in Equations (1)–(6).
Mathematics 13 03405 g008
Figure 9. The descendant subgraphs rooted at v 2 , v 7 , v 12 , and v 17 have the following properties: for v 2 , v ( M v 2 ) = 5 , e ( M v 2 ) = 4 and e ( r M r M v 2 ) = 1; for v 7 , v ( M v 7 ) = 5 , e ( M v 7 ) = 4 and e ( r M r M v 7 ) = 0 ; for v 12 , v ( M v 12 ) = 5 , e ( M v 12 ) = 2 and e ( r M r M v 12 ) = 0 ; for v 17 , v ( M v 17 ) = 4 , e ( M v 17 ) = 4 and e ( r M r M v 17 ) = 0 .
Figure 9. The descendant subgraphs rooted at v 2 , v 7 , v 12 , and v 17 have the following properties: for v 2 , v ( M v 2 ) = 5 , e ( M v 2 ) = 4 and e ( r M r M v 2 ) = 1; for v 7 , v ( M v 7 ) = 5 , e ( M v 7 ) = 4 and e ( r M r M v 7 ) = 0 ; for v 12 , v ( M v 12 ) = 5 , e ( M v 12 ) = 2 and e ( r M r M v 12 ) = 0 ; for v 17 , v ( M v 17 ) = 4 , e ( M v 17 ) = 4 and e ( r M r M v 17 ) = 0 .
Mathematics 13 03405 g009
Figure 10. An illustration of the residual multigraph depicted with a dashed line, and the descendant subgraph is depicted with solid lines. The descendant subgraph contains k vertices, d multiple edges, and multiple edges between the roots.
Figure 10. An illustration of the residual multigraph depicted with a dashed line, and the descendant subgraph is depicted with solid lines. The descendant subgraph contains k vertices, d multiple edges, and multiple edges between the roots.
Mathematics 13 03405 g010
Figure 12. For fixed parameters k, d, and p, the number of possible descendant multigraphs M p .
Figure 12. For fixed parameters k, d, and p, the number of possible descendant multigraphs M p .
Mathematics 13 03405 g012
Figure 13. Illustration of multigraphs with a unicentroid and bicentroid.
Figure 13. Illustration of multigraphs with a unicentroid and bicentroid.
Mathematics 13 03405 g013
Figure 14. (a) Running time of the proposed algorithm for ( n , Δ ) with n = 10 , 20 , , 70 and Δ = 1 , 50 , along with the SD of the running time for pairs ( n , Δ ) with fixed n and Δ = 1 , 2 , , 50 ; (b) number of tree-like multigraphs enumerated by the proposed algorithm for ( n , Δ ) with n = 10 , 20 , , 70 and Δ = 1 , 50 , along with the SD of the counts for pairs ( n , Δ ) with fixed n and Δ = 1 , 2 , , 50 .
Figure 14. (a) Running time of the proposed algorithm for ( n , Δ ) with n = 10 , 20 , , 70 and Δ = 1 , 50 , along with the SD of the running time for pairs ( n , Δ ) with fixed n and Δ = 1 , 2 , , 50 ; (b) number of tree-like multigraphs enumerated by the proposed algorithm for ( n , Δ ) with n = 10 , 20 , , 70 and Δ = 1 , 50 , along with the SD of the counts for pairs ( n , Δ ) with fixed n and Δ = 1 , 2 , , 50 .
Mathematics 13 03405 g014
Table 1. Summary of key studies on graph enumeration.
Table 1. Summary of key studies on graph enumeration.
ReferenceMethodGraph TypeKey Contribution
Pólya (1937) [15]CombinatoricsGeneral GraphsFoundational combinatorial method and cycle indices
Akutsu and Fukagawa (2005) [29]DpTrees, PlanarPolynomial time for bounded-degree trees; NP hard for planar graphs
Akutsu and Fukagawa (2007) [17]Branch-and-BoundTree-Like GraphsEnumeration from given frequency vector
Ishida et al. (2008) [22]Branch-and-BoundChemical GraphsNon-isomorphic tree-like chemical graph enumeration
Fujiwara et al. (2008) [18]Branch-and-BoundChemical GraphsEfficient performance for path frequency enumeration
Masui et al. (2009) [34]DPRooted/Unrooted TreesRanking, unranking, and enumeration methods
Imada et al. (2010) [33]DPOuterplanar GraphsStereoisomer enumeration in chemical graphs
Imada et al. (2011) [32]DPTree-StructuredStereoisomer enumeration of molecules
Shimizu et al. (2011) [23]Branch-and-BoundAcyclic ChemicalFeature-vector-based enumeration methods
Akutsu et al. (2012) [30]DPBounded Degree TreesTree-like graph enumeration with bounded degree
MacKay and Piperno (2014) [16]Branch-and-BoundGeneral GraphsEfficient graph isomorphism testing and enumeration
Rue et al. (2014) [31]DPSurface-EmbeddedSurface cut decomposition for graphs
He et al. (2016) [35]DP and BacktrackingChemical StructuresNaphthalene-containing structure enumeration
Haraguchi and Nagamochi (2019) [44]Polynomial DelayLabeled GraphsEnumeration of connectors and connected subgraphs
Azam et al. (2020) [39]DPTree-like MultigraphsCounting multigraphs with self-loops
Sun et al. (2022) [47]Linear-Time AlgorithmPlanar NetworksSubtree enumeration in planar two-tree networks
Maristany de las Casas et al. (2023) [42]DPGeneral GraphsSpanning tree problem approach
Tada and Haraguchi (2023) [45]Partition-BasedConnected SubgraphsLinear-delay enumeration of connected subgraphs
Yanhaona et al. (2023) [43]DpPlane 3-TreesSpanning tree enumeration
Ye et al. (2023) [28]Structural PruningBipartite GraphsBiclique counting in large graphs
Maudet and Danoy (2024) [25]Genetic ProgrammingGeneral GraphsBranching strategy improvement
Sciandra et al. (2024) [26]Graph ConvolutionalGeneral GraphsStructural information guided search
Labassi et al. (2024) [27]GNN-BasedGeneral GraphsAdaptive node selection methods
Shota and Haraguchi (2025) [46]SSD-BasedStrongly ConnectedLinear-delay subgraph enumeration
Qian and Uehara (2025) [48]Reverse Search AlgorithmWeighted TreesConstant-time enumeration algorithm
Ido et al. (2025) [41]DPChemical GraphsStructure generation from frequency vectors
Table 2. Experimental results for larger instances n 80 , showing average execution time and number of tree-like multigraphs computed by the proposed method.
Table 2. Experimental results for larger instances n 80 , showing average execution time and number of tree-like multigraphs computed by the proposed method.
( n , Δ ) Time (s)No. of Tree-like
Multigraphs
( n , Δ ) Time (s)No. of Tree-like
Multigraphs
(80, 10)6.91 3.73 × 10 44 (90, 10)8.80 4.26 × 10 49
(80, 20)45.25 1.02 × 10 52 (90, 20)56.26 3.02 × 10 57
(80, 30)139.57 6.53 × 10 57 (90, 30)179.61 4.55 × 10 63
(80, 40)340.35 4.52 × 10 62 (90, 40)411.81 6.89 × 10 68
(80, 50)628.20 6.78 × 10 66 (90, 50)805.91 2.14 × 10 73
(90, 51)Memory out
(100, 10)15.96 4.49 × 10 54 (110, 10)12.16 4.44 × 10 59
(100, 20)70.18 7.57 × 10 62 (110, 20)83.09 1.66 × 10 68
(100, 30)232.11 2.50 × 10 69 (110, 30)280.37 1.13 × 10 75
(100, 40)509.23 7.82 × 10 74 (110, 39)601.18 1.98 × 10 80
(100, 43)639.26 2.47 × 10 76 (110, 40)Memory out
(100, 44)Memory out
(120, 10)20.54 4.16 × 10 64 (130, 10)18.79 3.72 × 10 69
(120, 20)102.10 3.24 × 10 73 (130, 20)120.05 5.73 × 10 78
(120, 30)329.82 4.33 × 10 80 (130, 30)379.62 1.44 × 10 86
(120, 38)673.18 3.54 × 10 85 (130, 36)653.50 1.12 × 10 90
(120, 39)Memory out(130, 37)Memory out
(140, 10)20.98 3.19 × 10 74 (150, 10)23.20 2.65 × 10 79
(140, 20)146.69 9.33 × 10 83 (150, 20)155.67 1.41 × 10 89
(140, 30)494.81 4.22 × 10 91 (150, 30)506.93 1.11 × 10 97
(140, 35)680.32 1.03 × 10 95 (150, 34)722.01 7.38 × 10 99
(140, 36)Memory out(150, 35)Memory out
(160, 10)26.70 2.14 × 10 84 (170, 10)30.10 1.67 × 10 89
(160, 20)181.15 2.00 × 10 94 (170, 20)199.35 2.68 × 10 99
(160, 30)613.94 2.67 × 10 102 (170, 30)637.20 5.87 × 10 107
(160, 31)646.90 1.47 × 10 103 (170, 31) Memory out
(160, 32)Memory out
(180, 10)43.43 1.28 × 10 94 (190, 10)41.07 9.63 × 10 98
(180, 20)223.74 3.41 × 10 104 (190, 20)274.56 4.14 × 10 109
(180, 28)610.58 2.99 × 10 111 (190, 26)595.62 1.07 × 10 115
(180, 29)Memory out(190, 27)687.59 7.60 × 10 115
(190, 28)Memory out
(200, 10)47.08 7.09 × 10 103 (200, 20)309.53 4.82 × 10 114
(200, 25)546.71 2.12 × 10 119 (200, 26)636.43 1.62 × 10 120
(200, 27)Memory out
Table 3. Comparison of running times of the proposed algorithm and Nauty [16].
Table 3. Comparison of running times of the proposed algorithm and Nauty [16].
( n , Δ ) Number of MultigraphsTime (s) by Proposed MethodTime (s) by Nauty
(5, 10) 3.30 × 10 2 0.01270.0427
(5, 20) 1.95 × 10 3 0.08340.0442
(5, 30) 5.89 × 10 3 0.25770.0473
(5, 40) 1.32 × 10 4 0.58300.0519
(5, 50) 2.49 × 10 4 1.14720.0627
(6, 10) 2.06 × 10 3 0.02080.0469
(6, 20) 2.05 × 10 4 0.13380.0625
(6, 30) 8.76 × 10 4 0.40870.1264
(6, 40) 2.53 × 10 5 0.92710.2881
(6, 50) 5.86 × 10 5 1.81670.6028
(7, 10) 1.17 × 10 4 0.02910.0521
(7, 20) 1.93 × 10 5 0.18910.2442
(7, 30) 1.15 × 10 6 0.58821.2176
(7, 40) 4.26 × 10 6 1.33714.4479
(7, 50) 1.20 × 10 7 2.502412.5097
(8, 10) 6.37 × 10 4 0.04020.1252
(8, 20) 1.67 × 10 6 0.25661.9211
(8, 30) 1.36 × 10 7 0.788716.0670
(8, 40) 6.45 × 10 7 1.978278.7573
(8, 50) 2.21 × 10 8 3.4009294.2675
(9, 10) 3.26 × 10 5 0.05070.7339
(9, 20) 1.34 × 10 7 0.371117.5110
(9, 30) 1.49 × 10 8 1.0394205.9734
(9, 40) 8.91 × 10 8 2.37001282.1714
(9, 50) 3.70 × 10 9 5.8467Memory out
(10, 10) 1.61 × 10 6 0.08473.6110
(10, 20) 1.01 × 10 8 0.4711152.1980
(10, 30) 1.51 × 10 9 1.3675Memory out
(11, 10) 7.61 × 10 6 0.080114.9310
(11, 20) 7.17 × 10 8 0.50181293.4790
(11, 30) 1.43 × 10 10 1.7742Memory out
(12, 10) 3.50 × 10 7 0.109585.5969
(12, 20) 4.85 × 10 9 0.6919Memory out
(13, 10) 1.57 × 10 8 0.1144573.7060
(13, 15) 3.06 × 10 9 0.3242Memory out
(14, 10) 6.84 × 10 8 0.13194599.9461
(14, 11) 1.39 × 10 9 0.1689Memory out
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Ilyas, M.; Hayat, S.; Azam, N.A. Counting Tree-like Multigraphs with a Given Number of Vertices and Multiple Edges. Mathematics 2025, 13, 3405. https://doi.org/10.3390/math13213405

AMA Style

Ilyas M, Hayat S, Azam NA. Counting Tree-like Multigraphs with a Given Number of Vertices and Multiple Edges. Mathematics. 2025; 13(21):3405. https://doi.org/10.3390/math13213405

Chicago/Turabian Style

Ilyas, Muhammad, Seemab Hayat, and Naveed Ahmed Azam. 2025. "Counting Tree-like Multigraphs with a Given Number of Vertices and Multiple Edges" Mathematics 13, no. 21: 3405. https://doi.org/10.3390/math13213405

APA Style

Ilyas, M., Hayat, S., & Azam, N. A. (2025). Counting Tree-like Multigraphs with a Given Number of Vertices and Multiple Edges. Mathematics, 13(21), 3405. https://doi.org/10.3390/math13213405

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