% -*- Mode: TeX -*-
% This is plain TeX code.

The {\bf Lagrange's formula} for $n$-point interpolation of a polynom
is $$
    A(x) = \sum_{k=0}^{n-1} y_k
        {\displaystyle\prod_{j \neq k} (x - x_j) \over
         \displaystyle\prod_{j \neq k} (x_k - x_j)}.
$$
This formula is taken from the excellent book {\it Introduction to
Algorithms} by Thomas H.~Cormen, Charles E.~Leiserson, Ronald L.~Rivest.

To create an algorithm that performs polynom interpolation in
$O(n^2)$-time the trick is to compute the polynomial $B(x) =
\prod_{j=0}^{n-1} (x - x_j)$ in advance (which can be done in $O(n^2)$
time), and then for each $k$ compute $T(x) = B(x) / (x - x_k)$
($O(n)$ time), divide the result by $\prod_{j \neq k} (x_k - x_j)$
($O(n)$ time to compute the value, which can be done by computing
$T(x_k)$) and then add this to an accumulating sum ($O(n)$ time).

\bigskip
\hskip5em\vbox{\halign{#&#\hfil\cr
1       &Let $A(x) = 0$ (a zero degree polynomial)\cr
2       &Compute $B(x) = \prod_{j=1}^{n-1} (x - x_j)$\cr
3       &For each $k = 0,\ldots,n-1$, repeat steps 3--\cr
4       &\kern2em Let $T(x) = B(x) / (x - x_k)$\cr
5       &\kern2em Let $A(x) := A(x) + T(x) / T(x_k)$\cr}}
\bigskip

The net result is then $$O(n^2) + (n-1) * \left[O(n) + O(n) +
O(n)\right]\;=\; O(n^2).$$

\end
