Show that a linear operator can be written in terms of its spectral decomposition 
Let $\hat Q$ be an operator with a complete set of orthonomal eigenvectors:
  $$
\hat Q |e_n\rangle=q_n|e_n\rangle\ \ (n=1,2,3,...)
$$
  Show that $\hat Q$ can be written in terms of its spectral decomposition:
  $$
\hat Q=\sum_n q_n|e_n\rangle\langle e_n|.
$$

Firstly in consideration that $|\alpha\rangle$ can be written in the form of $|\alpha\rangle=\sum a_n|e_n\rangle$, so my solution is as follows
\begin{align}
\hat Q|\alpha\rangle & =\sum a_n\hat Q|e_n\rangle\\
                     & =\sum a_n(\hat Q|e_n\rangle)\\
&=\sum_n a_nq_n |e_n\rangle
\end{align}
I want to derive one equation like that
$$
\hat Q |\alpha\rangle=\{\text{something(operators in the form of components)}\}|\alpha\rangle
$$ 
So I get 
$$
\hat Q=\text{something}
$$
but I don't know what should I do nextly, so I hope someone can give me help and explain the mechanism to me.
 A: Hint: 
if $|e_i\rangle$ is the basis any vector $$|\alpha \rangle= \sum a_i |e_i \rangle$$
So, $\langle e_i|\alpha \rangle = a_i$ (Fourier inverse)
Apply $Q$ on both sides
$$Q|\alpha \rangle=\sum_i a_i Q|e_i \rangle$$
So, 
$$Q|\alpha \rangle=\sum_i a_i q_i|e_i \rangle$$
$$Q|\alpha \rangle=\sum_i \langle e_i|\alpha \rangle  q_i|e_i \rangle$$
$$Q|\alpha \rangle=\bigg [ \sum_i |e_i \rangle |\langle e_i| q_i  \bigg ]|\alpha \rangle$$
A: If I understood your question correctly there seems to be a confusion with the two summations. 
Since the basis is orthonormal we can say that, for any two basis vectors $|e_m\rangle$ and $|e_n\rangle$.
$$\langle e_m|e_n\rangle = \delta_{mn}$$
i.e $$\delta = 1, m=n$$ and $$\delta = 0, m\neq n$$
Lets expand the last equation in your question
$$Q|\alpha \rangle=\bigg [ \sum_i |e_i \rangle |\langle e_i| q_i  \bigg ]|\alpha \rangle$$
and write $|\alpha\rangle = \sum_{j} \alpha_j|e_j\rangle$
$$Q|\alpha \rangle=\bigg [ \sum_i |e_i \rangle \langle e_i| q_i  \bigg ]\sum_{j} \alpha_j|e_j\rangle$$
$$= \sum_i\sum_j q_i \alpha_j|e_i\rangle \langle e_i|e_j\rangle$$
$$= \sum_{ij} q_i \alpha_j \delta_{ij}|e_i\rangle$$
$$= \sum_i q_i \alpha_i |e_i\rangle$$
because when $i\neq j, \delta_{ij} = 0$  anyway.
A: First of all, when you introduce the second sum, your expression already contains a sum over 'n'. That means, you'll have to write $\sum_m a_m |e_m\rangle$. Then you can rearrange the terms in such a way that you get $\langle e_n | e_m \rangle$, and if you remember what that is you are as good as done with the calculation.
