Lilliana Livingston

2022-07-16

Passwords for a certain computer system are strings of uppercase letters. A valid password must contain an even number of X’s. Determine a recurrence relation for the number of valid passwords of length n. Note: 0 is an even number, so ABBC is a valid password.
Here’s a good way to think about it: to make a good password of length n you can either:
(a) add any non-X to the end of a good password of length $n-1$, or
(b) add an X to the end of a bad password of length $n-1$. For (b) you can use the Good = Total-Bad trick to count the number of bad passwords of length $n-1$.
*This is for an Introductory Discrete math course, so any sort of coding will not be helpful and I will not understand.
I also need to figure out the recursive solution for Xn, so if ${X}_{n}+1$ is shown, I have yet to understand how it applies to the recursive solution Xn. If you could PLEASE give me a STEP-FOR-STEP explanation on how this problem and the clues help answer this (throw in some examples as well), it would be so helpful to me. One thing for sure is I do not understand the n-1 part in the clues and how that applies to answering the question. Thus far, I have come up with ${X}_{n}=24\left(x\left(n-1\right)\right)+{26}^{n-1}$, but when I set $n=1$, I end up with 1, which from using paper and pencil, is not correct (x1 should equal 25, not zero)*

Franklin Frey

Expert

Step 1
Let G(n) represent the number of Good strings of length n, that is the number of strings where there are an even number of X's.
Let B(n) represent the number of Bad strings of length n, that is the number of strings where there are an odd number of X's.
Let T(n) represent the Total number of strings of length n.
It should be clear that $T\left(n\right)=G\left(n\right)+B\left(n\right)={26}^{n}$, seen from multiplication principle and induction.
It should also be clear that $T\left(1\right)=26$, that $G\left(1\right)=25$ and $B\left(1\right)=1$. Alternatively, you could note that $T\left(0\right)=G\left(0\right)=1$ and $B\left(0\right)=0$. These will be our "seed" values.
Step 2
We try to come up with a recursive definition for G(n). To do this, we suppose that we do not know the value for G(n) for the input of n specifically, but we know the value for all inputs strictly less than n (in particular for $n-1$).
We recognize that we can count how many good strings of length n there are from the fact that we can construct every good string of length n by using smaller strings. As the hint in the problem suggests, we break into cases based on what the final character of the string is.
Any good string of length n falls into exactly one of the following cases:
- The last character is not an X and the prefix string made up of all characters except the last one is a "good string" of length $n-1$ (which we know exactly how many there are as per our induction hypothesis). There are exactly $25×G\left(n-1\right)$ such strings in this case (pick what the last non-X character it is, and pick which prefix it is, apply multiplication principle).
- The last character is an X and the prefix string made up of all characters except the last one is a "bad string" of length $n-1$ (which we know exactly how many there are as per our induction hypothesis). There are exactly $1×B\left(n-1\right)$ such strings in this case (set the last character as X and then pick which prefix it is, apply multiplication principle).
Noting there is no overlap between the cases and noting that these cases are exhaustive and cover all possibilities, we get the following:
$G\left(n\right)=25×G\left(n-1\right)+1×B\left(n-1\right)$
Remembering that $T\left(n-1\right)=G\left(n-1\right)+B\left(n-1\right)={26}^{n-1}$ we can rewrite the $B\left(n-1\right)$ from the above as:
$G\left(n\right)=25×G\left(n-1\right)+\left({26}^{n-1}-G\left(n-1\right)\right)$
$G\left(n\right)=24×G\left(n-1\right)+{26}^{n-1}$
In your post you wrote "But when I set $n=1$, I end up with 1..."
$G\left(1\right)=24×G\left(1-1\right)+{26}^{1-1}=24×G\left(0\right)+{26}^{0}=24×1+1=25$ as expected. Remember that $G\left(0\right)=1$. You probably incorrectly assumed $G\left(0\right)=0$. The empty-string is technically considered to be a string, just like how the empty set is considered to be a set. There is exactly one string of length zero and it has an even number of X's (zero X's to be specific) so it counts as a good string in our problem.
If you wanted to you could continue the problem and come up with a closed form solution for G(n) which is not recursive. At a glance, it will be of the form $G\left(n\right)=c\cdot {24}^{n}+d\cdot {26}^{n}$ for some constants c,d which would take some algebra to find.

aanpalendmw

Expert

Step 1
Instead of finding a recursion formula (of recursion level one), let us give an exact formula (which is a recursion of level zero).
The alphabet has 25 (upper) letters $\ne X$, and also this X: Consider the binomial expansion of
If counts in degree k (i.e. the coefficient of ${X}^{k}$ is) the number of words/passwords with exactly k occurences of X. (Because the noncommutative expansion of $\left(A+B+\cdots +W+Y+Z\phantom{\rule{2em}{0ex}}+X{\right)}^{n}$ "shows" all words, and then we formally set $A=B=\cdots =W=Y=Z=1$.) To isolate all those words with an even number of X's, and prepair them for the counter we build:

Now we set $X=1$, getting the counter
Step 2
Examples: $C\left(0\right)=1$, the empty password, in accordance with the formula. $C\left(1\right)=\left(26+24\right)/2=25$, yes, the one-letter-X-password is forbidden. C(2) counts the password XX, and all $\alpha \beta$ with two $\alpha ,\beta$ non-X-letters. This is also $\frac{1}{2}\left({26}^{2}+{24}^{2}\right)=\frac{1}{2}\left(\left(25+1{\right)}^{2}+\left(25-1{\right)}^{2}\right)=\frac{1}{2}\sum _{±}\left({25}^{2}±2\cdot 25+{1}^{2}\right)={25}^{2}+{1}^{2}=C\left(2\right)$

Do you have a similar question?