How are the planets' classification as terrestrial planet or gas giant generally related to their densities?
There is some sort of relationship of density to this classification. Mean density for gas planets is far less than that for terrestrial planets. The ratio is nearly 1 : 5..
Density Table ( courtesy: NASA Planetary Table):
Mercury-5.427 Venus 5.243 Earth-5514 Mars 3.933
Jupiter-1.326 Saturn 0.687 Uranus-0.271 Neptune 1.638
The mean density for the terrestrial planets Mercury, Venus, Earth
and Mars is 5.038 gm/cc
The mean density for the gas planets Jupiter, Saturn, Uranus and
Neptune is 0.9805 gm/cc