First, it is observed that sound travels faster in denser mediums, therefore a sound wave will travel the fastest through solids. But again it is observed that because hot air is less dense sound passes through it faster than in cold air? It is totally opposite of the first case, how?
1 Answer
A typical formula for the speed of sound is $$v=\sqrt{\frac{K}{\rho}}.$$ The $K$ on the top line is a modulus of elasticity, a measure of how stiff the medium is when squeezed, and $\rho$ is the medium's density.
So it's not as simple as "the denser the medium the faster (or the slower!) sound travels". For example, steel is much denser than air; this in itself would make sound travel much more slowly in steel than in air, but the effective $K$ of steel is greater than that of air by an even larger factor than the density is greater, and sound actually travels faster in steel than in air.
In the case of gases, $K=\gamma p$ in which $\gamma$ is 1.4 for diatomic gases such as oxygen and nitrogen, and $p$ is the pressure. But, from the ideal gas equation $$p=\frac{n}{V} RT=\frac{nM}{V} \frac{RT}{M} \ \ \ \text{that is} \ \ p=\frac{RT}{M} \rho$$ in which $n$ is number of moles and M is molar mass.
Substituting into the first equation gives $$v=\sqrt{\frac{\gamma RT}{M}}.$$
So you can see that the speed of sound in a gas goes up as the square root of the Kelvin temperature.
It's easy to see why this should be… Sound travels because a movement of molecules (eg pushed by a loudspeaker) propagates through the gas. This motion is superimposed on the random motion of air molecules, whose rms speed is proportional to $\sqrt{T}$ and is usually much greater than the superimposed velocity, and so determines the speed at which the sound travels (passed on from molecule to molecule by collisions)!
Returning to your question: you can't explain how fast sound travels using just the idea of density. It's more complicated than that. But not very complicated!