All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Just Math
Counting words (Posted on 2022-04-27) Difficulty: 3 of 5
Given an alphabet of 3 letters i.e. a,b,c evaluate
the number of n-letter words containing even number of “a”s.

No Solution Yet Submitted by Ady TZIDON    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Analytic Solution | Comment 5 of 7 |
The set of words can be built recursively.  Let t(n) be the number of n character words containing even number of “a”s and let s(n) be  number of n character words containing odd number of “a”s.

Then a word in t(n) can be formed taking a word from t(n-1) and appending "b" or "c" or by taking a word from s(n-1) and appending "a".  Similarly, a word in s(n)  can be formed taking a word from s(n-1) and appending "b" or "c" or by taking a word from t(n-1) and appending "a".

Then we have a double recursion t(n) = 2*t(n-1) + s(n-1) and s(n) = 2*s(n-1) + t(n-1).  We also know that there are 3^n total words of length n, so s(n)+t(n) = 3^n.

Substitute s(n)+t(n) = 3^n into the recursion equations to get t(n) = t(n-1) + 3^(n-1) and s(n) = s(n-1) + 3^(n-1). Then subtract these two equations to get t(n) - s(n) = t(n-1) - s(n-1).  This final relation can be iterated upon itself to get t(n) - s(n) = t(n-1) - s(n-1) = .... = t(0) - s(0).

The empty string is the unique word of zero characters, and has zero "a"s which is even.  So t(0)=1 and s(0)=0.  Then t(n)-s(n) = 1.

Treat s(n)+t(n) = 3^n and t(n)-s(n) = 1 as a system of equations and solve.  Then t(n) = (3^n + 1)/2 and s(n) = (3^n - 1)/2.

  Posted by Brian Smith on 2022-04-27 09:54:50
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (6)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information