Evaluate $\displaystyle \int \limits_{0}^{\frac{\pi}{2}} \left|\sin x - \cos x\right| \; dx$
Let $I = \displaystyle \int \limits_{0}^{\frac{\pi}{2}} \left|\sin x - \cos x\right| \; dx$ $\;\;\; \cdots \; (1)$
$\text{Now, } \left|\sin x - \cos x\right| = \begin{cases}
\cos x - \sin x, & 0 < x < \dfrac{\pi}{4} \\\\
\sin x - \cos x, & \dfrac{\pi}{4} < x < \dfrac{\pi}{2}
\end{cases}$ $\;\;\; \cdots \; (2)$
$\therefore$ $\;$ In view of equation $(2)$, equation $(1)$ can be written as
$\begin{aligned}
I & = \int \limits_{0}^{\frac{\pi}{4}} \left(\cos x - \sin x\right) \; dx + \int \limits_{\frac{\pi}{4}}^{\frac{\pi}{2}} \left(\sin x - \cos x\right) \; dx \\\\
& = \int \limits_{0}^{\frac{\pi}{4}} \cos x \; dx - \int \limits_{0}^{\frac{\pi}{4}} \sin x \; dx + \int \limits_{\frac{\pi}{4}}^{\frac{\pi}{2}} \sin x \; dx - \int \limits_{\frac{\pi}{4}}^{\frac{\pi}{2}} \cos x \; dx \\\\
& = \left[\sin x\right]_{0}^{\pi / 4} + \left[\cos x\right]_{0}^{\pi / 4} - \left[\cos x\right]_{\pi / 4}^{\pi / 2} - \left[\sin x\right]_{\pi / 4}^{\pi / 2} \\\\
& = \sin \left(\dfrac{\pi}{4}\right) - \sin \left(0\right) + \cos \left(\dfrac{\pi}{4}\right) - \cos \left(0\right) \\\\
& \hspace{5em} - \cos \left(\dfrac{\pi}{2}\right) + \cos \left(\dfrac{\pi}{4}\right) - \sin \left(\dfrac{\pi}{2}\right) + \sin \left(\dfrac{\pi}{4}\right) \\\\
& = \dfrac{1}{\sqrt{2}} - 0 + \dfrac{1}{\sqrt{2}} - 1 - 0 + \dfrac{1}{\sqrt{2}} - 1 + \dfrac{1}{\sqrt{2}} \\\\
& = \dfrac{4}{\sqrt{2}} - 2 \\\\
& = 2 \sqrt{2} - 2 = 2 \left(\sqrt{2} - 1\right)
\end{aligned}$