[Math] Given an n*n adjacency matrix, calculate the number of triangles in a graph

adjacency matrixgraph theorymatricesNetwork

I got that if we calculate the eigenvalues of the adjacency matrix of the graph, and then sum all of the eigenvalues, then it will give the number of triangles in the graph.

Is this true, if not then please explain how I can use the eigenvalues of the adjacency matrix in order to compute the number of triangles in a graph.

The graph in question is undirected, connected and simple.

Best Answer

Not sure about eigenvalues, but triangles with an ordering on the vertices are in 1-1 correspondence with directed, 3-step paths from each vertex to itself. So the number of triangles is equal to the trace of $A^3$ divided by 6, since each triangle is counted twice (once in each direction) for each vertex in the triangle.