Counting the number of squares in a graph
There is a simple $O(n^4)$-time algorithm which I will let you discover yourself. A better algorithm follows from the following formula for the number of squares:
$$
\operatorname{Tr} (A^4) - \sum_i d_i^2,
$$
where $A$ is the adjacency matrix and $d_i$ is the degree of the $i$th vertex. Using this formula you can compute the number of squares in $O(n^\omega)$, where $\omega &lt; 2.373$ is the matrix multiplication constant.