In this paper, we focus on the perfect and total perfect codes of the non-coprime and coprime graphs associated to the dihedral groups and finite Abelian groups. We used the advantage of independent sets and tried to present the independent polynomial for them.