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!

You missed the hypothesis that the $a_i$ are pairwise distinct. Alternatively, consider the functionals $\eta_i$ with $P\mapsto P(a_i)$ in $V=(\Bbb R_{n-1}[X])^\ast$, and suppose $$\sum_{i=1}^n\lambda_i\eta_i=0$$
Evaluating at $1,X,X^2,\ldots,X^{n-1}$ we get $n$ equations $k=0,1,2,\ldots,n$. 
$$\sum_{i=1}^n\lambda_ia_i^k=0$$
Or $$\begin{pmatrix}1&1&\cdots&1\\a_1&a_2& \cdots&a_n\\\vdots&\vdots &\ddots&\vdots\\a_1^{n-1}&a_2^{n-1}&\cdots&a_n^{n-1}\end{pmatrix}\begin{pmatrix}\lambda_1\\ \lambda_2\\\vdots\\ \lambda_n\end{pmatrix}=\begin{pmatrix}0\\ 0\\\vdots\\ 0\end{pmatrix} $$
But since the $a_i$ are pairwise distinct, the Vandermonde matrix is invertible, which means ${\bf \lambda} =\bf 0$ as desired.
The claim follows from the fact your polynomials are precisely the predual basis, call it $B$, of the evaluations above which form a basis $B'$ for $V$. This observation also means that $$(f)_B=(\eta_1f,\ldots,\eta_n f)=(f(a_1),\ldots,f(a_n))$$
This is a general property: if $B^*=\{\varphi_1,\ldots,\varphi_n\}$ is the dual basis of $B=\{v_1,\ldots,v_n\}$, and if $v\in V$, $\varphi\in V^\ast$, then $$(v)_B=(\varphi_1(v),\ldots,\varphi_n(v))$$ $$(\varphi)_{B^\ast}=(\varphi(v_1),\ldots,\varphi(v_n))$$ and the proof is just like that exhibited in the accepted answer: evaluate, and use $\varphi_i(v_j)=\delta_{ij}$.
