Solution (source code)

= Solution

Apply successive <Householder reflections> supported on smaller trailing coordinate sets. At step $k=1,\ldots,n-2$, let $x$ be the entries in rows $k+1,\ldots,n$ of column $k$ of the current <symmetric matrix>. If $x\ne0$, part (c) gives an orthogonal reflection $H$ taking it to $ce_1$; if $x=0$, use the identity. Embed this as $Q_k=\operatorname{diag}(I_k,H)$ and replace the current matrix by $Q_k^TAQ_k$.

The first $k$ columns are unchanged by right multiplication. Left multiplication turns the tail of column $k$ into a vector supported only in row $k+1$. Previously treated columns have zero entries throughout this trailing coordinate set, so their zeros are preserved. Symmetry makes the matching row zeros appear as well. After the final step all entries below the first subdiagonal, and by symmetry above the first superdiagonal, vanish.

The product $Q=Q_1\cdots Q_{n-2}$ is orthogonal, and
$$
\boxed{Q^TAQ\text{ is tridiagonal}}.
$$
Restricting each transformation to its trailing coordinates is what preserves earlier zero patterns.