For the first graph, it is easy to see that it is a negative sine wave shifted up by $1/2$. So $a_1=0$, $b_1=-1$. Since there are no other signals added, $a_2=b_2=0$.
To find the unknown values of the second graph, first look at the basic shape. The graph's basic shape resembles a sine wave with period $2\pi$. There is no other effects on this frequency, so $a_1=0$ and $b_1=1$. Now look at the higher frequency effects. Since $n=2$, the period of these waves is half the period of the $n=1$ wave. With $y(0)=0$, we know the cosine term $a_2=0$ (since adding them together would yield a non-zero result at $x=0$). The sharp peaks seem to indicate that the sine term should be positive. This can be verified by inspecting the region around $x=\pi$. You can see that $y(\pi)=0$ and the function is increasing at that point, indicating that $b_2=1$.