shifts and deflation
The plain QR algorithm works, but it can be painfully slow — it converges only linearly, governed by ratios of eigenvalue magnitudes that may be close to 1. Two refinements transform it from a curiosity into the fast, reliable engine inside every linear-algebra library. They are shifts (to make convergence explosively fast) and deflation (to stop wasting work on eigenvalues you have already found). Together they are the difference between an algorithm that limps and one that flies.
A shift exploits the same insight as inverse iteration. Instead of factoring A, you factor A - sigma I = Q R and form R Q + sigma I (which keeps the eigenvalues but recentres the convergence around sigma). Choosing sigma close to an eigenvalue makes the bottom-right subdiagonal entry shrink by a factor near zero each step — the convergence becomes quadratic, or cubic for symmetric matrices. The standard choice is the Wilkinson shift: the eigenvalue of the trailing 2x2 corner block that is closest to the bottom-right entry, which is robust even when two eigenvalues are close. Deflation is the bookkeeping partner: as soon as a subdiagonal entry h_{k+1,k} drops below a tolerance (essentially round-off times the matrix norm), you declare the corresponding diagonal entry a converged eigenvalue, set that subdiagonal to exactly zero, and continue working only on the smaller leading block. The active problem shrinks one or two eigenvalues at a time.
The payoff is enormous: with shifts each eigenvalue typically converges in about 2 or 3 iterations, and deflation means later eigenvalues cost progressively less, so the whole spectrum of an n-by-n matrix is found in O(n^3) work. There is a subtle honesty point: deflating splits the matrix, but a tiny nonzero subdiagonal entry that you set to zero introduces a backward error — you have found the exact eigenvalue of a slightly perturbed matrix. Because that perturbation is at the round-off level and the algorithm is backward stable, this is exactly the accuracy you should expect and accept.
On a tridiagonal symmetric matrix, the trailing 2x2 corner block has two eigenvalues; the Wilkinson shift sigma is whichever is nearer the corner entry. Subtracting sigma I, doing one QR step, and adding sigma I back drives the last subdiagonal entry down by roughly its cube each step. Within two or three iterations it is below tolerance; you deflate that eigenvalue and repeat on the (n-1)x(n-1) leading block.
A good shift gives quadratic/cubic convergence per eigenvalue; deflation peels off converged eigenvalues and shrinks the work.
Setting a tiny subdiagonal to zero is a deliberate backward error of size about machine-epsilon times ||A|| — legitimate and expected, not cheating. A poorly chosen shift can stall (this is why the Wilkinson shift, not the naive Rayleigh shift, is the default for symmetric problems), and real nonsymmetric matrices need a double shift to avoid complex arithmetic.