Covariance Formula: The formula for covariance is:
$$
\operatorname{Cov}(X, Y)=E[X Y]-E[X] E[Y]
$$
We need to calculate $E[X], E[Y]$, and $E[X Y]$.
Calculate Marginal Probabilities: First, we find the marginal probabilities (the total probabilities for $X$ and $Y$ ) by summing the rows and columns.
\begin{array}{llll}
P(X, Y) & \mathrm{Y}=0 & \mathrm{Y}=1 & \mathbf{P}(\mathrm{X}) \\
\mathbf{X=0} & 0.1 & 0.4 & \mathbf{0.5} \\
\mathbf{X=1} & 0.3 & 0.2 & \mathbf{0.5} \\
\mathbf{P}(\mathbf{Y}) & \mathbf{0.4} & \mathbf{0.6} & 1.0
\end{array}
Calculate $E[X]$ :
$$
\begin{aligned}
& P(X=0)=P(X=0, Y=0)+P(X=0, Y=1)=0.1+0.4=0.5 \\\\
& P(X=1)=P(X=1, Y=0)+P(X=1, Y=1)=0.3+0.2=0.5 \\\\
& E[X]=(0 \times P(X=0))+(1 \times P(X=1))=(0 \times 0.5)+(1 \times 0.5)=0+0.5=0.5
\end{aligned}
$$
Calculate $E[Y]$ :
$$
\begin{aligned}
& P(Y=0)=P(X=0, Y=0)+P(X=1, Y=0)=0.1+0.3=0.4 \\\\
& P(Y=1)=P(X=0, Y=1)+P(X=1, Y=1)=0.4+0.2=0.6 \\\\
& E[Y]=(0 \times P(Y=0))+(1 \times P(Y=1))=(0 \times 0.4)+(1 \times 0.6)=0+0.6=0.6
\end{aligned}
$$
Calculate $E[X Y]$ :
$$
\begin{aligned}
& E[X Y]=(0 \times 0 \times P(0,0))+(0 \times 1 \times P(0,1))+(1 \times 0 \times P(1,0))+(1 \times 1 \times \\\\
& P(1,1))=0+0+0+(1 \times 1 \times 0.2)=0.2 \\\\
& \operatorname{Cov}(X, Y)=E[X Y]-E[X] E[Y]=0.2-(0.5 \times 0.6)=0.2-0.3=-0.1
\end{aligned}
$$