Solution:
Concept: A wave reaching the end of a string is reflected. The reflected wave must satisfy the condition at the end: at a fixed end (the limit of a much denser medium) the displacement is always zero; at a free end (the limit of a much rarer medium, a light ring sliding on a smooth rod) there is no sideways force on the end, so the slope of the string there is always zero.
(a) Step 1 — Define standing waves. When two identical waves (same amplitude, frequency and wavelength) travel along the same line in opposite directions, for example a wave and its reflection, they superpose to form a wave pattern that does not advance. It has fixed nodes (no vibration) and antinodes (largest vibration) and carries no net energy in any direction. Such a wave is called a standing or stationary wave.
(b) Step 2 — Write the incident and reflected waves. Let the boundary be at x=0 and let the incident wave travel along +x towards it:
yi=asin(ωt−kx)
The reflected wave travels along −x and has the form yr=asin(ωt+kx+δ), where δ is the phase change on reflection.
Step 3 — Apply the condition at a denser (rigid) boundary. The end cannot move, so the total displacement at x=0 must be zero at every instant:
asinωt+asin(ωt+δ)=0
sin(ωt+δ)=−sinωt
This holds for all t only if:
δ=π
So the reflected wave is yr=−asin(ωt+kx): a crest returns as a trough. This is the phase change of π.
Step 4 — Apply the condition at a rarer (free) boundary. The free end feels no sideways force, so the slope ∂x∂y of the string at x=0 must be zero:
∂x∂yi+∂x∂yr=0
−akcosωt+akcos(ωt+δ)=0
This holds for all t only if:
δ=0
So the reflected wave is yr=asin(ωt+kx): a crest returns as a crest, with no phase change.
Step 5 — Show both cases. The figure shows a pulse reflected (i) at a fixed end, inverted, and (ii) at a free end, upright.

Note: At a junction of two real strings only part of the wave is reflected, but the reflected part is inverted when the second string is denser and upright when it is rarer, just as at these two limiting ends.
Therefore, (a) a standing wave is the non-advancing pattern formed by two identical waves travelling in opposite directions; (b) at a denser (rigid) boundary the zero-displacement condition forces a phase change of π on reflection, while at a rarer (free) boundary the zero-slope condition gives reflection with no phase change.