  We design and analyze an adaptive $hp$-finite element method (hp-AFEM) in
dimensions $n=1,2$. The algorithm consists of iterating two routines:
hp-NEARBEST finds a near-best $hp$-approximation of the current discrete
solution and data to a desired accuracy, and REDUCE improves the discrete
solution to a finer but comparable accuracy. The former hinges on a recent
algorithm by Binev for adaptive $hp$-approximation, and acts as a coarsening
step. We prove convergence and instance optimality.
