In this paper we present an algebraic study concerning the general second order linear differential equation with polynomial coefficients. By means of Kovacic's algorithm and asymptotic iteration method we find a degree independent algebraic description of the spectral set: the subset, in the parameter space, of Liouville integrable differential equations. For each fixed degree, we prove that the spectral set is a countable union of non accumulating algebraic varieties. This algebraic description of the spectral set allow us to bound the number of eigenvalues for algebraically quasi-solvable potentials in the Schrödinger equation.