Speed of sound may appear to increase with the density of medium, as sound waves are mechanical waves and depend on the transmission of disturbance from one molecule to the next along the path.
However the exact and mathematical reason is as follows.
Velocity of soundThe Young's modulus in solids is much higher
than the bulk modulus in liquids or gases, Hence the velocity in solids is much higher than in liquids or in gases.
Same way the bulk modulus of liquids is much higher t
han that of gases, hence the speed of sound is higher in liquids. This is so in spite of the formula with density appearing in the denominator.