Suppose that $X$ is an $m \times n$ matrix and that the matrix $X^TX$ is invertible.
$H = X(X^TX)^{-1}X^T$
where $X^T$ is transpose of $X$; $(X^TX)^{-1}$ is inverse of $X^TX$
we are asked to show that
$\text{tr}(H) = n$.
By considering $H^2v$, where $v$ is an eigenvector of $H$, show that the eigenvalues of $H$ must be either $0$ or $1$.