Theory:

The compressions and rarefactions of a longitudinal wave travel through a medium. Assume that a compression travelling from left to right in the air reaches a rigid wall. On the rigid wall, the compression exerts a force $$F$$. The wall, in turn, has an equal and opposite reaction on the air molecules, $$R$$ $$=$$ $$– F$$. As a result, near the rigid wall, a compression occurs. A compression that travels towards a rigid wall is thus reflected as a compression. That is, the direction of compression is reversed.

Compression and rarefaction

Reflection at the boundary of a rarer medium:

Consider a wave travelling through a solid medium and striking the solid-air interface. On the surface of the rarer medium, the compression exerts a force $$F$$. The surface of the separation surface is pushed backwards because a rarer medium has a lower resistance to any deformation. A rarefaction occurs at the interface because the particles of the rarer medium are free to move. As a result, compression is reflected as rarefaction, which moves from right to left.

Let us know what is denser medium and rarer medium?

Rarer medium:

Rarer medium refers to a medium in which the velocity of sound increases in comparison to other medium (Water is rarer compared to air).

Denser medium:

Denser medium refers to a medium in which the sound velocity decreases when compared to other medium (In terms of sound, air is denser than water).