In perturbation calculations using basis states defined in terms of spherically symmetric potentials it is often necessary to simplify complicated expressions involving n-j symbols. A well known graphical technique can be used to aid in this process. We represent the graphs by their incidence matrices, so that the algebraic manipulations can be carried out by matrix arithmetic. It is shown that the sequence of operations required to simplify a given graph can be determined from structural considerations based on the properties of certain polynomials in the adjacency matrix. This provides a method of performing complete perturbation calculations of this type on a computer.