    # Linear time algorithm to check the singularity of block graphs

A block graph is a graph in which every block is a complete graph. Let G be a block graph and let A(G) be its (0,1)-adjacency matrix. Graph G is called nonsingular (singular) if A(G) is nonsingular (singular). Characterizing nonsingular block graphs is an interesting open problem proposed by Bapat and Roy in 2013. In this article, we give a linear time algorithm to check whether a given block graph is singular or not.

## Authors

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Let be a undirected graph with vertex set and edge set . Let the cardinality (also called the order of ) be equal to . The adjacency matrix of is the square matrix of order defined by

 aij={1if the vertices i,j are connected by an edge,0if i=j or i,j are not connected by an edge,

where A graph is called nonsingular (singular) if is nonsingular (singular), that is, the determinant of is nonzero (zero). The rank of , denoted by is the rank of the adjacency matrix . If has full rank, that is, , then is nonsingular, otherwise, it is singular. The nullity of , denoted by

is equal to the number of zero eigenvalues of

. By the rank-nullity theorem Thus a zero nullity of a graph implies that it is nonsingular while a positive nullity implies that it is singular. A cut-vertex of is a vertex whose removal results in an increase in the number of connected components. Let and be graphs on disjoint sets of vertices. Their disjoint union is the graph A coalescence of graphs and is any graph obtained from the disjoint union by identifying a vertex of with a vertex of , that is, merging into a single vertex . If , and have loops of weights respectively, then in the coalescence will have a loop of weight .

A block in a graph is a maximal connected subgraph that has no cut-vertex (, p.15). Note that if a connected graph has no cut-vertex, then it itself is a block. The blocks and cut-vertices in any graph can found in linear time . A block in a graph is called a pendant block if it has one cut-vertex of . Two blocks are called adjacent blocks if they share a cut-vertex of . A complete graph on vertices is denoted by . If every block of a graph is a complete graph then it is called a block graph. An example of block graph is given in Figure 1(a), where the blocks are the induced subgraph on the vertex-sets , and . For more details on the block graphs see (, Chapter 7).

A well-known problem, proposed in 1957, by Collatz and Sinogowitz, is to characterize graphs with positive nullity . Nullity of graphs is applicable in various branches of science, in particular, quantum chemistry, Hückel molecular orbital theory [9, 14] and social networks theory . There has been significant work on the nullity of undirected graphs like trees [6, 8, 10], unicyclic graphs [12, 16, 12], and bicyclic graphs [3, 5, 23]. It is well-known that a tree is nonsingular if and only if it has a perfect matching. Since a tree is a block graph, it is natural to investigate in general which block graphs are nonsingular. The combinatorial formulae for the determinant of block graphs are known in terms of size and arrangements of its blocks [4, 18, 17]

. But, due to a myriad of the possibility of sizes and arrangements of the blocks it is difficult in general to classify nonsingular or singular block graphs. In

, some classes of singular and nonsingular block graphs are given. However, it is still an open problem. In this paper, we give a linear time algorithm to determine whether a given graph is singular or not.

Thanks to the eminent computer scientist Alan Turing, the matrix determinant can be computed in the polynomial time using the decomposition of the matrix, where is a lower triangular matrix, is an upper triangular matrix, is a permutation matrix. Interestingly, the asymptotic complexity of the matrix determinant is the same as that of matrix multiplication of two matrices of the same order. The theorem which relates the complexity of matrix product and the matrix determinant is as follows.

###### Theorem 1.1

 Let be the time required to multiply two matrices over some ring, and be an matrix. Then, we can compute the determinant of in steps.

Rank, nullity is also calculated using decomposition, hence their complexities are also the same as that of the matrix determinant or product of two matrices of the same order. The fastest matrix product takes time of [7, 22, 13]. In this article, we give a linear time algorithm to check whether a given block graph of order , is singular or nonsingular (full rank). The algorithm is linear in . We will not make use of matrix product or elementary row/column operations during any stage of the computation, instead, we prove first results using elementary row/column operation on matrices and use them to treat pendant blocks of the block graphs.

The rest of the article is organised as follows. In Section 2, we mention some notations and preliminaries used in the article. In Section 3, we give necessary and sufficient condition for any block graph to be nonsingular by using prior results of elementary row/column operation given in Section 2. In Section 4, we provide an outline for Algorithm 1 and provide some examples in support of it. A proof of the correctness of Algorithm 1 is given in Section 5.

## 2 Notations and preliminary results

If is a subgraph of graph , then denotes the induced subgraph of on the vertex subset . Here, is the standard set-theoretic subtraction of vertex sets. If consists of a single vertex , then we write for .

denote the all-one matrix, all-one column vector, zero matrix, zero column vector of suitable order, respectively.

denotes a -column vector of suitable order. denotes the diagonal matrix of order , where the -th diagonal entry is . If a graph has no vertices (hence no edges) we call it a void graph.

###### Theorem 2.1

Consider a matrix

 M=⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣x11…11x2⋱⋮⋮⋱⋱11…1xn⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦=J−D, (1)

where

1. If exactly one of is equal to 1, then is nonsingular.

2. If any two (or more) of are equal to 1, then is singular.

3. If . Let

 S=n∑i=111−xi.

Then

1. is nonsingular if and only if .

2. if and is any real number, then the matrix

 [MjjTxn+1]

is nonsingular.

4. If is nonsingular, then the matrix

 ~M=[MjjTα]

can be transformed to the following matrix using elementary row and column operations

 [MooTα+γ],

where

 γ={−SS−1if xi≠1,i=1,…n,−1if exactly one of x1,…,xn is equal to 1. (2)
###### Proof
1. Without loss of generality, let . By subtracting the 1-st row from the rest of the rows, can be transformed to the matrix,

 ⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣11…10(x2−1)⋱⋮⋮⋱⋱10…0(xn−1)⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦,

whose determinant is nonzero.

2. In this case two rows (or columns) are the same.

1. We have

 D−J=D1/2(I−D−1/2JD−1/2)D1/2,
 D−1/2JD−1/2=D−1/2jjTD−1/2=(D−1/2j)(D−1/2j)T.

Let The is nonsingular if and only if is nonsingular. Since the eigenvalues of are and the eigenvalues of the matrix are and hence it is nonsingular if and only if That is is nonsingular if and only if

 n∑i=111−xi≠1.
1. If as this implies

 S+11−xn+1≠1.

Hence the result follows by 3(a).

2. If then result follows by 1.

1. If . Let We have,

 (I−yyT)(I+tyyT)=I+(t−1−t||y||2)yyT,

and therefore if

 (I−yyT)−1=I+11−||y||2yyT.

Thus if is invertible, where then, by the above,

 (J−D)−1=−(D−J)−1=−D−1/2(I+11−||y||2yyT)D−1/2,

where

 jTM−1j =−jTD−1/2(I+11−||y||2yyT)D−1/2j =−yT(I+11−||y||2yyT)y=||y||2||y||2−1.

Let

 P=[I−M−1joT1].

Then

 PT~MP=[MooTα+γ],

where

 γ=−jTM−1j=−||y||2||y||2−1=−SS−1.
2. When exactly one of is equal to 1, without loss of generality, we can write

 ~M=⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣11…111x2⋱⋮⋮⋮⋱⋱111…1xn11…11α⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦

On subtracting the first column from the last column, and subsequently subtracting the first row from the last row. We get the following matrix,

 ~M=⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣11…101x2⋱⋮⋮⋮⋱⋱101…1xn00…00α−1⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦,

hence

###### Lemma 1

[18, Lemma 2.3] If is a coalescence of and at a vertex having loop of weight , then

 det(G)=det(G1)det(G2∖v)+det(G1∖v)det(G2)−αdet(G1∖v)det(G2∖v).

## 3 Transformation of the adjacency matrix

Elementary row/column operations transform the adjacency matrix into another matrix which may have nonzero diagonal entries. The graph corresponding to can be obtained by a change of weights on the edges and addition of loops on the vertices in according to the elementary row/column operations on . This can be seen as follows. Let be a pendant block of a block graph , having the cut-vertex of . As reordering the vertices of does not change the rank of , we can write the adjacency matrix as the follows.

 A(G)=⎡⎢⎣A(B∖v)jOTjT0wTOwA(G∖B)⎤⎥⎦.

Let the pendant block have vertices.

1. If as is the complete graph on vertices, it is nonsingular. All the diagonal elements in are zero. Using Theorem 2.1(4), is transformed to the following matrix.

 M1=⎡⎢ ⎢⎣A(B∖v)oOToT−m−1m−2wTOwA(G∖B)⎤⎥ ⎥⎦.

Let

 M12=[−m−1m−2wTwA(G∖B)].

We have, As is nonsingular, is nonsingular if and only if is nonsingular.

2. If In this case is a coalescence of with at the vertex . As is nonsingular and is singular, using Lemma 1, is nonsingular if and only if is nonsingular.

In view of the above discussion, in order to know whether block graph is singular or nonsingular, we need to further examine the matrices for , for . Note that, , is the matrix corresponding to the induced subgraph on the vertex-set of , with a loop on the vertex having weight . By selecting a pendant block from the graph (for ) or the graph corresponding to ( for ) we can further investigate the rank of . This process will continue until we cover all the blocks of . The matrix corresponding to the pendant block at any step is of the form in Theorem 2.1. Hence we use the prior results from Section 2 to check whether is singular or not. Examples are given in Figure 1 (nonsingular), Figure 2 (singular) and Figure 3 (singular), where at each step a pendant block is chosen for the elementary row/column operations. The detailed algorithm is given in the next section.

## 4 Algorithm

For the purpose of the algorithm we first define two auxiliary operations on a set of sets of integers.

### 4.1 Auxiliary operations

Let where, is a set of positive integers. We define two operations on

###### Example 1

Let . Consider Then,

The cardinality of a set is denoted by . In Example 1, the cardinality of is 3.

### 4.2 Algorithm

Given a block graph , with blocks We have a set which is the set of vertex-sets of the blocks in . is the set of cut-vertex-sets of the blocks Let denote the vertex set of the block and be the set of cut-vertices in it. That is, we have

 BV={V(B1),…,V(Bk)},
 CV={C(B1),…,C(Bk)}.

A vertex-set in is pendant vertex-set if contains exactly one cut-vertex, that is, . Let be the number of times the cut-vetex appears in . Let be the weight assigned to the vertex of . We first give an outline of the procedure to check whether a given block graph is singular or nonsingular. We start with the sets . Initially,

BEGIN- If has no pendant vertex-set, go to END. Otherwise, pick a pendant vertex-set , where the cut-vertex is .

Check if

1. If false:

1. If for more than one is 1, then is singular. STOP.

2. If for exactly one is 1, then induced subgraph on is nonsingular. DO

1. .

2. If then else,

BEGIN the algorithm for .

2. If true: Let . Check If

1. If true: Then the induced subgraph on is nonsingular. DO

1. .

2. If else,

BEGIN the algorithm for .

2. If false: then induced subgraph on is singular. DO

1. .

BEGIN the algorithm for .

END: Let be the induced subgraphs of on the vertex sets in with the addition of weighted loops added in the process. If is nonsingular for all then is nonsingular else is singular. Note that, each of is of form in Theorem 2.1, hence, using Theorem 2.1, it is checked in linear time whether is singular or nonsingular.

The algorithm of the above outline is given in Algorithm 1. Where the function GSING takes as input, and makes recursive use of basic arithmetic, auxiliary operations which take at the most linear time, and check whether the block graph is singular or not. Now we provide some examples in support of Algorithm 1.

###### Example 2

Consider the block graph given in Figure 1(a).

 BV={{3,5,6,7},{1,10,8,9},{3,4,1,2},{2,11,12}},
 CV={{3},{1},{3,1,2},{2}},

1. 1st call to . As 3 is the only vertex in in , the corresponding vertex-set in is selected as pendant vertex-set. Next, induced graph on vertex set is investigated. , as . Then will be updated to , that is vertex will now have a loop of weight . Now,

 BV={{1,10,8,9},{3,4,1,2},{2,11,12}},

As,

 CV={{1},{1,2},{2}}.
2. 2nd call to . As 1 is the only vertex in in , the corresponding vertex-set in is selected as pendant vertex-set. Next, induced graph on vertex set is investigated. As . Then will be updated to , that is vertex will now have a loop of weight .

 BV={{3,4,1,2},{2,11,12}},

As,

 CV={{2},{2}}.
3. 3rd call to . As 2 is the only vertex in in , the corresponding vertex-set in is selected as pendant vertex-set. Next, induced graph on vertex set is investigated. As . Then will be updated to , that is vertex will now have a loop of weight .

 BV={{2,11,12}},

As,

 CV={}.
4. 4-th call to . As is empty, there is no pendant vertex-set. We need to investigate the induced graph on vertex set (with loop on 2). As and hence . Which means is nonsingular, hence is nonsingular.

###### Example 3

The steps for block graph in Figure 2(a) are similar to the steps in Example 2 for block graph in Figure 1(a). In the 4-th call to , we need to investigate the induced graph on vertex set (with loops). As and hence . Which means is singular, hence is singular.

###### Example 4

Consider block graph in Figure 3(a). We have,

 BV={{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9}},
 CV={{1},{1},{1},{1},{1},{1},{1},{1}},

1. 1st call to . As 1 is the only vertex in in , the corresponding vertex-set in is selected as pendant vertex-set. Next, induced graph on vertex set is investigated. As . Thus

 BV={{3},{4},{5},{6},{7},{8},{9}},
 CV={{},{},{},{},{},{},{}},
2. 2nd call to . As is empty, there is no pendant vertex-set. We need to investigate the induced graphs on vertex-sets in . But as all are singleton vertices without loops. Hence the block graph is singular.

## 5 Proof of correctness

Just before -th calling of function in Algorithm 1, the adjacency matrix is transformed to the matrix which is of the form

 Mi=⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣A(G1)⋱A(Gi−1)A(Gi∖i)jjTαwTwM⋆⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦.

where each are some induced subgraph of block (possibly with loops) whose vertex-set selected as pendant vertex-set during -th calling of . It is clear that if any one of is singular, then is singular. Note that if any of is empty then it is to be considered as nonsingular by convention. Now, is the induced subgraph (possibly with loops) whose vertex-set is selected as pendant vertex-set during -th calling of . Let be the cut-vertex in the selected pendant vertex-set. Let be the weight of loop at if there is no loop at then is the matrix corresponding to induced subgraph (with possible loops) of , on the vertex-set . Thus, if are nonsingular, then is nonsingular if and only if the following submatrix is nonsingular,

 ~M=⎡⎢⎣A(Gi∖i)jOjTαwTOTwM⋆⎤⎥⎦. (3)

is of form , where is diagonal matrix,

1. If more than one diagonal entries of are equal to 1, then as, at least two rows and two columns of are same, it is obvious that is singular.

2. If exactly one diagonal entry of is 1, the using Theorem 2.1.1., is nonsingular. By Theorem 2.1.4., can be transformed to the following matrix,

 ⎡⎢⎣A(Gi∖i)oOoTα−1wTOTwM⋆⎤⎥⎦.

Thus, is nonsingular if and only if the following nonsingular matrix is nonsingular,

 [α−1wTwM⋆].
3. If and . Then is nonsingular. By Theorem 2.1.4., can be transformed to the following matrix,

 ⎡⎢ ⎢⎣A(Gi∖i)oOoTα−SS−1wTOTwM⋆⎤⎥ ⎥⎦.

Thus, is nonsingular if and only if the following nonsingular matrix is nonsingular,

 [α−SS−1wTwM⋆].
4. If is singular. Then by Theorem 2.1.3.(b), is nonsingular. The graph corresponding to is a coalescence of with the induced graph (possibly with loop) of .

As, is singular and is nonsingular, by Lemma 1, is nonsingular if and only if is nonsingular.

This completes the proof.

Acknowledgments
The authors are grateful to Dr. Cheng Zheng for his valuable comments and suggestions.

## References

•  Aho, A.V., Hopcroft, J.E.: The design and analysis of computer algorithms. Pearson Education India (1974)
•  Bapat, R.B.: Graphs and Matrices. Springer (2014)
•  Bapat, R.: A note on singular line graphs. Bull. Kerala Math. Assoc 8(2) (2011)
•  Bapat, R., Roy, S.: On the adjacency matrix of a block graph. Linear and Multilinear Algebra 62(3), 406–418 (2014)
•  Berman, A., Friedland, S., Hogben, L., Rothblum, U.G., Shader, B.: An upper bound for the minimum rank of a graph. Linear Algebra and its Applications 429(7), 1629–1638 (2008)
•  Cvetkovic, D.M., Doob, M., Sachs, H.: Spectra of graphs, volume 87 of pure and applied mathematics (1980)
•  Davie, A.M., Stothers, A.J.: Improved bound for complexity of matrix multiplication. Proceedings of the Royal Society of Edinburgh: Section A Mathematics 143(02), 351–369 (2013)
•  Fiorini, S., Gutman, I., Sciriha, I.: Trees with maximum nullity. Linear algebra and its applications 397, 245–251 (2005)
•  Gutman, I., Borovicanin, B.: Nullity of graphs: an updated survey. Selected topics on applications of graph spectra, Math. Inst., Belgrade pp. 137–154 (2011)
•  Gutman, I., Sciriha, I.: On the nullity of line graphs of trees. Discrete Mathematics 232(1-3), 35–45 (2001)
•  Hopcroft, J.E., Tarjan, R.E.: Efficient algorithms for graph manipulation (1971)
•  Hu, S., Xuezhong, T., Liu, B.: On the nullity of bicyclic graphs. Linear Algebra and its Applications 429(7), 1387–1391 (2008)
• 

Le Gall, F.: Powers of tensors and fast matrix multiplication. In: Proceedings of the 39th international symposium on symbolic and algebraic computation. pp. 296–303. ACM (2014)

•  Lee, S.L., Li, C.: Chemical signed graph theory. International journal of quantum chemistry 49(5), 639–648 (1994)
•  Leskovec, J., Huttenlocher, D., Kleinberg, J.: Signed networks in social media. In: Proceedings of the SIGCHI conference on human factors in computing systems. pp. 1361–1370. ACM (2010)
•  Nath, M., Sarma, B.K.: On the null-spaces of acyclic and unicyclic singular graphs. Linear Algebra and its Applications 427(1), 42–54 (2007)
•  Singh, R., Bapat, R.B.: B-partitions, application to determinant and permanent of graphs. Transactions on Combinatorics 7(3), 29–47 (2018)
•  Singh, R., Bapat, R.: On characteristic and permanent polynomials of a matrix. Spec. Matrices 5, 97–112 (2017)
•  Singh, R., Zheng, C., Shaked-Monderer, N., Berman, A.: Nonsingular block graphs: An open problem. arXiv preprint arXiv:1803.03947 (2018)
•  Von Collatz, L., Sinogowitz, U.: Spektren endlicher grafen. In: Abhandlungen aus dem Mathematischen Seminar der Universität Hamburg. vol. 21, pp. 63–77. Springer (1957)
•  West, D.B.: Introduction to graph theory, vol. 2. Prentice hall Upper Saddle River (2001)
•  Williams, V.V.: Breaking the coppersmith-winograd barrier. E-mail address: jml@ math. tamu. edu (2011)
•  Xuezhong, T., Liu, B.: On the nullity of unicyclic graphs. Linear algebra and its applications 408, 212–220 (2005)