The expected length of code for one encoded symbol is
![\displaystyle\sum_{\alpha\in\{w,x,y,z\}}p_\alpha\ell_\alpha](https://img.qammunity.org/2020/formulas/mathematics/college/vtqynb2x00fxpktogfoanst8m68l1qiuf3.png)
where
is the probability of picking the letter
, and
is the length of code needed to encode
.
is given to us, and we have
![\begin{cases}\ell_w=1\\\ell_x=2\\\ell_y=\ell_z=3\end{cases}](https://img.qammunity.org/2020/formulas/mathematics/college/7a78ohls41sl7lkltydyuv54631v02b7nn.png)
so that we expect a contribution of
![\frac12+\frac24+\frac{2\cdot3}8=\frac{11}8=1.375](https://img.qammunity.org/2020/formulas/mathematics/college/z9sou2ulf47eyn6ix42iba5pavrm4nlwd4.png)
bits to the code per encoded letter. For a string of length
, we would then expect
.
By definition of variance, we have
![\mathrm{Var}[L]=E\left[(L-E[L])^2\right]=E[L^2]-E[L]^2](https://img.qammunity.org/2020/formulas/mathematics/college/x1ainur8rb09lpvs0v7y9bzd0b7ueskpaj.png)
For a string consisting of one letter, we have
![\displaystyle\sum_{\alpha\in\{w,x,y,z\}}p_\alpha{\ell_\alpha}^2=\frac12+\frac{2^2}4+\frac{2\cdot3^2}8=\frac{15}4](https://img.qammunity.org/2020/formulas/mathematics/college/73lezrhonae6n2u76zcitxak9hdsrp8w78.png)
so that the variance for the length such a string is
![\frac{15}4-\left(\frac{11}8\right)^2=(119)/(64)\approx1.859](https://img.qammunity.org/2020/formulas/mathematics/college/1bwdd943vlwgqsles120ly63nkei07wync.png)
"squared" bits per encoded letter. For a string of length
, we would get
.