Divided differences

Clear[f, x, p, xlist, ylist];
f[x_] = Exp[-x^2];
xlist = {0. , 0.5, 1. , 1.5, 2. };
ylist = f[xlist];
n = Length[xlist];
l[k_, x_] := 
        Product[(x - xlist[[i]])/(xlist[[k]] - 
                  xlist[[i]]), {i, 1, 
              k - 1}]*
Product[(x - 
                  xlist[[i]])/(xlist[[k]] - 
                  xlist[[i]]), {i, k + 1, 
              n}];
p[x_] = Sum[ylist[[k]]*l[k, x], {k, 1, n}];

Collect[p[x], x]

Clear[f, x, xlist, ylist, ddlist];
f[x_] = Exp[-x^2];
xlist = {0. ,  .5, 1. , 1.5, 2. };
ylist = f[xlist];
n = Length[xlist];
ddlist = {xlist, ylist}

Do[ddlist = 
        Append[ddlist, 
          Table[(ddlist[[k + 1, l]] - 
                  ddlist[[k + 1, l + 1]])/(xlist[[l]] - 
                  xlist[[l + k]]), {l, 1, 
              n - k}]], 
{k, 1, n - 1}]

ddlist

coefflist = Table[ddlist[[k, 1]], {k, 2, n + 1}]

p1[x_] = 
      Sum[coefflist[[k]] 
          Product[(x - xlist[[i]]), {i, 1, k - 1}], {k, 1, 
          n}]

Collect[p1[x], x]

p[x] - p1[x]

Simplify[%]

Plot[{p1[x], f[x]}, {x, 0, 2}]