1. Introduction
In Haruo Hosoya’s seminal paper, a molecular-graph based structure descriptor is proposed that nowadays is known under the name Hosoya index [
1]. It is well-known that several physicochemical properties of chemical structures are well correlated with the Hosoya index of the corresponding molecular graphs. In particular, it is used to predict, from the structure of molecules, some of their physico-chemical properties such as boiling points, entropies, heat of vaporization, and
-electron energy [
1,
2].
The mathematical investigations on the Hosoya index are often related to trees, see for example [
3,
4,
5,
6,
7,
8]. Note also that there is a strong connection between the energy of a tree and its Hosoya index [
9]. It is established that the general problem of determining the Hosoya index is #P-complete even for planar graphs [
10]. On the other hand, if the graph is known to be a tree, there are efficient solutions.
In [
11], Zhang and co-authors proposed an algorithm that allows computation of the Hosoya index of a tree in linear time. The algorithm uses a relatively complex pre-processing which for a given tree computes the Prüfer code of the corresponding labeled tree. As noted already by the authors, another troublesome aspect of the proposed algorithm is its necessity of computation with fractions. Moreover, it was shown in [
12] that the values of the characteristic polynomial of a tree can be computed in linear time, which implies that a computation of the Hosoya index of a tree can be done within the same time-bound; however, an explicit algorithm has not been presented.
It has been demonstrated that the Hosoya index can be computed efficiently for some graphs derived from trees. In particular, for an arbitrary tree
T, a closed-form expression is presented for the Hosoya index of the fractal graphs
and
[
13].
Since a graph is entirely determined by specifying either its adjacency structure or its incidence structure, it is natural to state the specification of a graph in matrix form. By associating a matrix with a graph, one can also use selected graph invariants as molecular descriptors. This approach was initiated in a work by Randić, where a matrix based on another well-known molecular-graph structure descriptor, the Wiener index, is proposed [
14]. Later, Randić used an analogous approach, based on the Hosoya index, for acyclic systems, which yields the concept of the Hosoya matrix [
15].
The paper is organized as follows. In the next section, we give some definitions and concepts needed in this paper. In
Section 3, we follow the idea presented in [
12] to give a recursive expression for the Hosoya index of a tree. Using this result, we present a linear-time algorithm for computing the Hosoya index of a graph of this class. In
Section 4, we apply the previous section’s approach to provide a recursive formula for an entry of the Hosoya matrix. The results allow the computation of the Hosoya matrix in constant time per entry of the matrix.
2. Preliminaries
Let be a graph, possessing n vertices and m edges. The set of edges is called a matching of G if any two edges of X have no vertex in common. A matching of G with k edges is called a k-matching of G.
A subset of vertices is independent if no two vertices of I are adjacent. The number of distinct k-element independent vertex sets is denoted by . Note that and .
The
Hosoya index of a graph
G, denoted by
, is defined as the total number of matchings of
G. Let
be the number of
k-matchings of
G and set
. The Hosoya index can be formulated as
Let be a graph and . Then denotes the graph obtained from G by removing vertices of . If , i.e., is composed of a single vertex, we will write instead of . Analogously, if and , then denotes the graph obtained from G by removing vertices of . If , we will write instead of .
A tree is a connected graph without cycles. If are vertices of a tree T, then T admits exactly one path between u and v. We shall denote this path by .
Let
T be a tree with the vertex set
. The Hosoya matrix of a tree
T is the
matrix
, where
-entry of
is the Hosoya index of the graph obtained from
T by removing the edges of the path
[
15]. More formally, if
, then
Let v be a vertex of a graph G. Then or simply denote the set of vertices adjacent to v in G.
A rooted tree is a tree in which one vertex is distinguished from the others and called the root. If r is a root of a tree T, then denotes the corresponding rooted tree. Let be a vertex of . As already stated, denotes the path between r and v in . If u is a vertex of adjacent to v, then u is a parent of v and v is a child of u. If u is a parent of v and w parent of u, then w is a grandparent of v. Note that every vertex of a rooted tree admits at most one parent and grandparent. A vertex z is a descendant of v if v is in the path from z to r. A vertex v of a tree T, and all its descendants induce a subgraph of denoted by . It is clear that is a tree. Note that can be seen as a rooted subtree of with the root v.
If v is a vertex of , then denotes the set of children of v. If , let denote the parent of v. If , then v is a leaf of .
3. Hosoya Index
3.1. Recursive Formula for Computing the Hosoya Index
The results of this subsection are obtained by using an approach similar to the work of Mohar where the characteristic polynomial of a tree is studied [
12].
The following three results are well-known [
1,
16].
Proposition 1. Let be an edge of a graph G. Then Proposition 2. Let G be a graph composed of two disjoint components and . Then Proposition 3. Let v be a vertex of a graph G. Then We also need the following
Proposition 4. Let v and u be vertices of a tree T. Then
(ii) If v is the parent of u in , then Proof. (i) If T is a single vertex, the claim immediately follows. Otherwise, note that . It follows that is composed of connected components , for all . Proposition 2 now yields the assertion.
(ii) We can see that
is composed of two sets of connected components: one corresponds to components of
with the exception of
, while the other corresponds to
. Let us denote the first set of connected components by
. By (i), we have
From Proposition 2 now it follows that
If u is a leaf, then is the graph composed of connected components , for all . Since , the case is settled.
If
u is not a leaf, then
is the graph composed of connected components
and
, for all
and
. From Proposition 2 and (i) then it follows
This assertion concludes the proof. □
Theorem 1. Let v and r be (not necessarily distinct) vertices of a tree T. Then Proof. If v is a leaf, then is a single vertex and the case is settled.
If v is not a leaf, then note that . By Proposition 3, we have Proposition 4 now completes the proof. □
3.2. Algorithm for Computing the Hosoya Index
Let
v be a vertex of a nonempty tree
T. The data structure of the rooted tree
is given by Algorithm 1, where
and
represent the list of children of
v and the parent of
v in
, respectively.
Algorithm 1. Rooted(T, v, C, p) |
1. := the list comprised of all vertices of ; 2. For all do begin 2.1 Remove v from ; 2.2 Rooted(T, w, C); 2.3 ; end; end. |
Let v be a vertex of T and . If is represented by a (doubly connected) adjacency list, then we may remove v from in constant time. It is easy to see now that the time complexity of Rooted is linear.
Algorithm 2 computes the Hosoya index
of a tree
T with respect to a root
v. Before the algorithm is applied, the algorithm Rooted is called for the vertex
v. Thus, for every vertex
u in
, the rooted tree is represented by the list of children
.
Algorithm 2. Hosoya(v, C, Z, ) |
1. ; 2. if then begin ; EXIT; end; 3. for all do Hosoya(w, C, Z, ); 4. for all do ; 5. ; 6. for all do begin 6.1 6.2 if then 6.2.1 for all do ; 6.3 end; end. |
Theorem 2. Let T be tree of order n. Then algorithm Hosoya computes the Hosoya index of T in time and space.
Proof. The validity of the algorithm follows from Theorem 1. The algorithm computes vectors Z and , such that the entry (resp. ) represents (resp. . The algorithm also maintains the variable , which for represents the value of .
If v is a leaf in T, then and is set to one. Otherwise, the algorithm is recursively called for each child of v in Step 3. Note that the call of the algorithm for a vertex w computes the Hosoya index of the corresponding subtree . Thus, after Step 3 is executed, the Hosoya index is already computed for all subtrees of v. Next, is computed in Step 4. This gives the initial value of assigned in Step 5, while the sum is computed in Step 6. Steps 6.1 and 6.2 compute the value of . If u is a leaf, then and the value of remains equal to one. Otherwise, the value of is equal to after Step 6.2 is executed. In Step 6.3, the value of is multiplied by and divided by ; thus, the value added to in this step is equal to . This assertion completes the proof of the correctness of the algorithm.
For the time complexity first note that the time complexity of a single recursive call neglecting recursive calls (in Step 3) and neglecting the Steps 4 and 6 is clearly constant. Since the number of recursive calls of the algorithm equals the number of vertices of the tree, we have to show that the total number of operations executed in Steps 4 and 6 is linear in the number of vertices. This number can bounded above by the number of entries of the vector Z used by the algorithm. In Step 4, the values of , are used, while in Step 6.2.1, for , the entries , are used. Since every vertex v of a rooted tree admits at most one parent and grandparent, the corresponding entry is used at most three times: twice when Hosoya is called for the parent of v (Steps 4 and 6.3) and once when Hosoya is called for the grandparent of v (Step 6.2.1).
It follows that the total number of operations executed in Steps 4 and 6 is bounded above with some constant multiplied by the number of vertices of T.
Since the space complexity of the algorithm is clearly linear, the proof is complete. □
Note that the parameter p of the algorithm Rooted as well as the parameter of the algorithm Hosoya are not used for the computation of the Hosoya index. These parameters will be needed in the next section.
3.3. Example
As an example of the execution of the algorithm Hosoya observe the three
T with the vertex set
depicted in
Figure 1. We demonstrate the algorithm for the root 4. Note that before the algorithm is applied, the algorithm Rooted is called for the vertex 4.
Since 4 is not a leaf, the algorithm is recursively called for the vertices 3, 8, and 11 (the neighbors of 4) in Step 3. The recursion stops when a leaf is reached and the corresponding entry of the vector
Z is set to one. We therefore obtain
. For the vertex 2 we then obtain
in Step 4. Since
and
are both empty, Step 6.2.1 is never executed and
remains equal to one. The final value
is therefore obtained in Step 6.3, where for the vertices 1 and 5 the value one is added to the current value of
. Analogously, for the vertex 3 we obtain
in Step 4. Since
, we have
for
and
for
in Step 6.2. Finally, for
and
we add
and
to
in Step 6.3. These operations give
. The other values are obtained in an analogous manner. Thus, we obtain
,
, and
. The Hosoya index of a (sub)tree
(resp. the value of
) is shown at the upper left-hand side (resp. the right hand side) of the vertex
v in
Figure 1.
An intuitive explanation of the algorithm Hosoya for a tree T rooted at r is as follows.
All the entries of the vector Z that correspond to leaves of are set to one.
If v is a vertex of such that the Hosoya indices are already computed for all descendants of v, the computation of goes as follows:
- (a)
we multiply the Hosoya indices of all children of v and get the value of which is also the initial value of ;
- (b)
for every child u of v we multiply the Hosoya indices of all children of u and the Hosoya indices of all children of v with the exception of u. The obtained product is added to the current value of .
Consider again the rooted tree
in
Figure 1 and suppose that the Hosoya indices are already computed for all descendants of 4. For Step a., we obtain the initial value of
, which equals
. For Step b., we have
4. Hosoya Matrix
We will show that the Hosoya matrix of a tree of order n can be computed in time.
4.1. Recursive Formula for Computing the Hosoya Matrix
Proposition 5. If is an edge of a tree T, then Proof. Note first that
is composed of two connected components:
and
. Proposition 2 yields
By Proposition 1, we have
The assertion now follows immediately from Proposition 4. □
Theorem 3. If is a path in a tree T, then Proof. If , then this is Proposition 5.
If , we first show that is composed of connected components: , and the graph . We use induction on k. If , then is a graph composed of components: and . Let us assume that the proposition holds for all paths of length less than k, and let and . By the induction hypothesis, is composed of components , and . Since is composed of two connected components, and , and since the edge belongs to the tree , the assertion easily follows.
By Proposition 5, we have
and
Since is composed of connected components: , and the graph , Proposition 2 completes the proof. □
Corollary 1. Let be a path in a tree T. If Proof. By Theorem 3, we have to show that
. We use induction on
k. If
, then
and the assertion is trivial. Let
and assume that the claim holds for
. By Proposition 5,
Since by the induction hypothesis we have
the assertion follows. □
4.2. Algorithm for Computing the Hosoya Matrix
Algorithm 3 computes the entries of the
r-th row of the Hosoya matrix for the tree
T. In other words, the algorithm for the rooted tree
computes the value
for every
. If
v is a vertex of
, the list
represents the children of
v, while
represent the parent of
v. Vectors
Z and
for entries
and
represent
and
in
, respectively.
Algorithm 3. Row(v, r, C, p, Z, , ) |
1. if then begin 1.1 ; 1.2 ; 1.3 ; end 2. else begin 2.1 ; 2.2 ; 2.3 ; end; 3. for all do Row(w, r, C, p, Z, , ); end. |
Proposition 6. Let be a vertex of a tree T. Then algorithm Row computes the r-th row of the Hosoya matrix of T in linear time.
Proof. The correctness of the algorithm is based on Corollary 1. Note that and represent the parent of v and the children of v, respectively. The algorithm maintains variables and representing the values and of Corollary 1, respectively. We first consider the following two cases.
A. If , the correctness easily follows. The algorithm sets the values of and to one and , respectively.
B. If r is the parent of v, the value of remains equal to one after Step 2.1 is executed, since is set to in case A. The new value of is established in Step 2.2., while Step 2.3 provides the correct value of .
Since in the above cases the correct value of is computed, the correctness for other cases follows from Corollary 1.
For the time complexity, note that the number of recursive calls of the algorithm equals the number of vertices of . Since the time complexity of a single call of the algorithm (neglecting the recursive calls) is constant, the assertion follows. □
Algorithm 4 computes the Hosoya matrix
for the tree
T with the vertex set
.
Algorithm 4. Hosoya matrix(T, ) |
1. for ton do begin 1.1 Rooted(T, i, C, p); 1.2 Hosoya(i, Z, C, ); 1.3 Row(i, i, C, p, Z, , ); end; end. |
Theorem 4. Let T be tree of order n. Then algorithm Hosoya matrix computes the Hosoya matrix of T in time and space.
Proof. For every vertex , the algorithm creates the rooted tree in Step 1.1. The needed values and are then computed for every vertex v of in Step 1.2. Finally, all entries of the i-th row of the Hosoya matrix are computed in Step 1.3.
Since the time complexity of the algorithms Rooted, Hosoya, and Row is linear, the time and space bound of the algorithm Hosoya matrix easily follow. □
4.3. Example
Observe again the three
T with the vertex set
depicted in
Figure 1. We demonstrate the execution of the algorithm Row for the vertex 4 in the sequel. Note that before the algorithm is applied, the algorithm Hosoya, which computes the vectors
Z and
, is called for the vertex 4.
: , , .
: , , .
: , , .
: , , .
: , , .
: , , .
: , , .
: , , .
: , , .
: , , .
: , , .
5. Conclusions
Quantitative structure–property and structure–activity relationships of molecular compounds are frequently modeled using the molecular topological features of these compounds. In that regard, topological indices are crucial for investigating chemical compounds to grasp chemical structures’ fundamental topology.
In this paper, we have obtained efficient algorithms for computing the Hosoya index and the Hosoya matrix on an arbitrary acyclic graph. Both algorithms are optimal in the sense that the running time of an algorithm is constant per a fundamental essential item of the input: a vertex (for the computation of the Hosoya index) and an entry of the matrix (for the computation of the Hosoya matrix). The complexity of the presented algorithm for computing the Hosoya index of a tree is within the same time bound as some previously presented procedures. That said, the algorithm presented in this paper is much simpler than its predecessor given in [
11] and does not require pre-processing.
It is worth noticing that both presented algorithms exploit the recursive nature of a tree. Thus, a similar approach could be applied for computing the Hosoya index and the Hosoya matrix of tree-like graphs, e.g., cactus graphs, and of graphs derived from trees. Moreover, the presented concepts could initiate studies of efficient methods of computation for other topological indices, especially the ones that are closely connected to the Hosoya index, particularly the Merrifield–Simons index [
17,
18], the energy of a graph [
3], and the matching energy of a graph [
19].