Algebraic structure of quantum gravity and the classification of the gravitational anomalies