0
$\begingroup$

Using only the 26 standard English letters, construct a recurrence for the number of strings there are of length n that meet the following requirement: There is never a 'z' that comes before an 'a' in the string.

Examples of strings to count: alcatraz, amazon, xyzzy, induction

Examples of strings not to count: arizona, zynga, pizzeria

I've tried to take all possible strings of length n, 26^n, and subtract out the unwanted strings, but I can't figure out how to count the unwanted strings either.

1 Answers 1

0

A good idea is to work with the last occurence of an $a$

There is $25^{k-1} \times 25^{n-k}$ strings with an a in last position $k$ :you have 25 choice for each position before $k$ (no z), and 25 choices after (no a). There is also $25^n$ strings without an a

So, the total number of such strings is

$$N_n = 25^n + \sum_{k=1}^n 25^{k-1} \times 25^{n-k} = 25^n + \sum_{k=1}^n 25^{n-1} = 25^n + n 25^{n-1} = (n+25) 25^{n-1}$$

  • 0
    There are 26 strings of length 1 that match the criterion, but (1+1)25^(1-1) is equal to 2. For length 2, there are 675 strings, but your answer would give 75.2017-01-29
  • 0
    @Connor : you're right. What was wrong is that there is $25^n$ string without a, and not $25^{n-1}$, so the correct formula is $(n+25)25^{n-1}$. Will correct2017-01-29
  • 0
    One more thing, the question technically asked for a recurrence. I'm happy with your answer, but just for anybody else who looks at this, could you add it to your answer? I've calculated it to be a(n) = 25*a(n-1) + 25^(n-1) based on your answer. Thank you so much2017-01-29