We are counting the number of strings of length n over the alphabet {0, 1, 2} such that no two consecutive 2s appear.
Let’s denote:
Nₙ = |Sₙ| = number of valid strings of length n.
Part (a): Compute N₃
We can enumerate all valid strings of length 3 with no two consecutive 2s.
Total strings without restriction: 3³ = 27.
We subtract those that have at least one occurrence of “22” as a substring.
But since n=3 is small, we can just generate or count carefully.
Alternatively, use recursion or case analysis.
Let’s do it by cases based on positions.
Better approach: Use recurrence (even for part a)
Let’s define:
Let aₙ = number of valid strings of length n ending in 0 or 1
Let bₙ = number of valid strings of length n ending in 2
Then total Nₙ = aₙ + bₙ
Recurrence:
-
To form a string of length n ending in 0 or 1: we can append 0 or 1 to any valid string of length n-1. So:
aₙ = 2 * Nₙ₋₁
-
To form a string of length n ending in 2: we must append 2 to a string of length n-1 that ends in 0 or 1 (not 2). So:
bₙ = aₙ₋₁
Thus:
Nₙ = aₙ + bₙ = 2*Nₙ₋₁ + aₙ₋₁
But since aₙ₋₁ = 2*Nₙ₋₂, we get:
Nₙ = 2*Nₙ₋₁ + 2*Nₙ₋₂
Wait — let me double-check that.
Actually:
From above:
aₙ = 2 * Nₙ₋₁
bₙ = aₙ₋₁ = 2 * Nₙ₋₂
So:
Nₙ = aₙ + bₙ = 2*Nₙ₋₁ + 2*Nₙ₋₂
Is that right?
Wait — bₙ = aₙ₋₁, and aₙ₋₁ = 2 * Nₙ₋₂, yes.
So recurrence:
Nₙ = 2·Nₙ₋₁ + 2·Nₙ₋₂
But let’s verify with small n.
Base Cases:
n=1:
Strings: "0", "1", "2" → all valid → N₁ = 3
n=2:
All pairs except "22".
Total: 3² = 9, minus 1 invalid → N₂ = 8
List them: 00,01,02,10,11,12,20,21,22 → exclude 22 → 8 valid. ✔️
Now check recurrence for n=3:
N₃ = 2N₂ + 2N₁ = 28 + 23 = 16 + 6 = 22
Let’s verify by counting manually.
Total strings: 27
Invalid ones: those containing “22” as substring.
In length 3, “22” can occur starting at position 1 or 2:
- Positions 1-2: “22x” → x can be 0,1,2 → 3 strings: 220,221,222
- Positions 2-3: “x22” → x can be 0,1,2 → 3 strings: 022,122,222
But 222 is counted twice.
So total invalid = 3 + 3 - 1 = 5
Thus valid = 27 - 5 = 22 ✔️
✅ So N₃ = 22
Part (b): Compute N₁₀
We have recurrence:
Nₙ = 2·Nₙ₋₁ + 2·Nₙ₋₂
With:
N₁ = 3
N₂ = 8
Compute up to N₁₀:
N₃ = 28 + 23 = 16 + 6 = 22
N₄ = 222 + 28 = 44 + 16 = 60
N₅ = 260 + 222 = 120 + 44 = 164
N₆ = 2164 + 260 = 328 + 120 = 448
N₇ = 2448 + 2164 = 896 + 328 = 1224
N₈ = 21224 + 2448 = 2448 + 896 = 3344
N₉ = 23344 + 21224 = 6688 + 2448 = 9136
N₁₀ = 29136 + 23344 = 18272 + 6688 = 24960
✅ So N₁₀ = 24,960
Part (c): General formula for Nₙ
We have linear recurrence:
Nₙ = 2·Nₙ₋₁ + 2·Nₙ₋₂, for n ≥ 3
With N₁ = 3, N₂ = 8
This is a homogeneous linear recurrence with constant coefficients.
Characteristic equation:
r² - 2r - 2 = 0
Solve:
r = [2 ± √(4 + 8)] / 2 = [2 ± √12]/2 = [2 ± 2√3]/2 = 1 ± √3
So general solution:
Nₙ = A·(1 + √3)ⁿ + B·(1 - √3)ⁿ
Use initial conditions to solve for A and B.
For n=1:
N₁ = 3 = A(1+√3) + B(1−√3) → Eq (1)
For n=2:
N₂ = 8 = A(1+√3)² + B(1−√3)²
Compute (1+√3)² = 1 + 2√3 + 3 = 4 + 2√3
(1−√3)² = 1 − 2√3 + 3 = 4 − 2√3
So:
8 = A(4 + 2√3) + B(4 − 2√3) → Eq (2)
Now solve system:
Eq (1): A(1+√3) + B(1−√3) = 3
Eq (2): A(4+2√3) + B(4−2√3) = 8
Let’s write:
Let x = A, y = B
Eq1: x(1+√3) + y(1−√3) = 3
Eq2: x(4+2√3) + y(4−2√3) = 8
Multiply Eq1 by 2:
2x(1+√3) + 2y(1−√3) = 6 → 2x + 2x√3 + 2y − 2y√3 = 6
Eq2: 4x + 2x√3 + 4y − 2y√3 = 8
Subtract doubled Eq1 from Eq2:
[4x + 2x√3 + 4y − 2y√3] − [2x + 2x√3 + 2y − 2y√3] = 8 − 6
→ (4x−2x) + (2x√3−2x√3) + (4y−2y) + (−2y√3 + 2y√3) = 2
→ 2x + 2y = 2 → x + y = 1 → y = 1 − x
Plug into Eq1:
x(1+√3) + (1−x)(1−√3) = 3
Expand:
x + x√3 + (1−x)(1−√3) = 3
Compute (1−x)(1−√3) = 1·(1−√3) − x(1−√3) = 1−√3 − x + x√3
So total:
x + x√3 + 1 − √3 − x + x√3 = 3
Simplify:
(x − x) + (x√3 + x√3) + 1 − √3 = 3
→ 2x√3 + 1 − √3 = 3
→ 2x√3 = 2 + √3
→ x = (2 + √3)/(2√3)
Rationalize denominator:
Multiply numerator and denominator by √3:
x = [ (2 + √3)√3 ] / (2·3) = [2√3 + 3] / 6
Similarly, y = 1 − x = 1 − (2√3 + 3)/6 = (6 − 2√3 − 3)/6 = (3 − 2√3)/6
So:
A = (3 + 2√3)/6
B = (3 − 2√3)/6
Therefore, closed-form formula:
Nₙ = [(3 + 2√3)/6] · (1 + √3)ⁿ + [(3 − 2√3)/6] · (1 − √3)ⁿ
We can write this neatly as:
Nₙ = \frac{(3 + 2\sqrt{3})(1 + \sqrt{3})^n + (3 - 2\sqrt{3})(1 - \sqrt{3})^n}{6}
✅ This is the general formula.
Final Answers:
(a) N₃ = 22
(b) N₁₀ = 24,960
(c) Nₙ = \frac{(3 + 2\sqrt{3})(1 + \sqrt{3})^n + (3 - 2\sqrt{3})(1 - \sqrt{3})^n}{6}