Let $W_n$ be the set of all words of length n, on alephbet {a,b,c}. Let $L$ be the maximal length of consecutive $a$ letters in a word.
A. Find the generating function of the number of words in $W_n$ such as $L<3$.
B. Find the generating function of the number of words in $W_n$ such as $L<k$.
C. Find the expectation of $L$, i.e $W(q,x)=\sum_n \sum_\pi x^n q^{L(\pi)}$. Then find its asymptotic.
My solution:
A. Every word in $W_n$= "empty word" or "a ( )" or "b(every word)" or "c(every word)". Let $x$ count a lenght of a single number.
So, $W(x)=1+A_1(x) + 2xW(x)$
"a()" ="a" or "aa( )" or "ab(every word)" or "ac(every word)".
So, $A_1(x)=x+A_2(x)+2x^2W(x)$
"aa( )= "aa" or "aab(every word)" or "aac(every word)".
So, $A_2(x)=x^2+2x^3W(x)$.
Affer substituting we get that the gf is:
$W(x)=\frac{1+x+x^2}{1-2x-2x^2-2x^3}=\frac{1-x^3}{1-3x+2x^4}$.
B. As we did in part A: Now it is the generalized problem given in A.
$W(x)=1+A_1(x)+2xW(x)$
$A_1(x)=x+A_2(x)+2x^2W(x)$
$A_2(x)=x^2+A_3(x)+2x^3W(x)$
$A_3(x)=x^3+A_4(x)+2x^4W(x)$ . .
$A_{k-1}(x)=x^{k-1}+2x^kW(x)$
After solving this, we get:
$W_k(x)=\frac{1-x^k}{1-3x+2x^{k+1}}$
C.Let $x$ count the length of a single letter, $q$ counts a letter $a$. We can do the same approach as part B, and see that:
$W_k(q,x)=\frac{1-(qx)^k}{1-(q+2)x+2q^kx^{k+1}}$.
Then, we need to find the coefficients of $W(1,x)=W(x)$ And, $[d/dq W_k(q,x)]_{q=1}$ Then, their proportion will be the expectation. Another way, is to look at $W^{L+1}-W_L$ then $E=\sum_L L*(W_{L+1}-W_L$). But both ways are complicated for me, with these not simple generatinh functions.
How can the coefficients in the two generating functions be calculated (and analyzed asymptotically)? Or in other words how can the expectation be computed and analyzed asymptoticaly?