Lagrange basis functions as bases of Polynomials Space Suppose $L$ be a Vector Space of Polynomials of $x$ of degree $\leq n-1$ with coefficients in the field $\mathbb{K}$.
Define $$g_i(x) :=\prod _ {{j=1},{j\neq i}}^n \frac{x-a_j}{a_i-a_j}$$ Show that the polynomials $g_1(x), g_2(x),...,g_n(x)$ form a basis of L. Furthermore, show that coordinates of polynomial $f$ in this basis are $\{f(a_1),f(a_2),...,f(a_n)\}.$
To show that the polynomials are the bases, I need to show that they span $L$ and that they are linearly independent. I thought showing that any element in the set $\{1,x,x^2,...,x^{n-1}\}$ belongs to the span of $\{g_1(x), g_2(x),...,g_n(x)\}$ would be enough to show the $g_1(x), g_2(x),...,g_n(x)$ spans $L.$ But I don't know how to do this! Also, linear independence seems to be tougher!

Choose arbitrary $f\in L$. Let be $$\tilde{f}(x) = \sum_{i = 1}^{n}f(a_i)g_i(x)\text{.} $$
For every $x\in \{a_1,\dots, a_n\}$ we have $f(x) = \tilde{f}(x)$, so the polynomial
$p= f - \tilde{f}$ has $n$ zeros and $\deg p \leq n-1$, so $p(x) = 0$ for every $x\in \mathbb{R}$. So $g_i$ span $L$. We know that $\dim L = n$, so they must be linearly independendent.
