Counting Strings Over a Finite Alphabet

A string's positions give ordered choices. Constraints on length, repetition, or required symbols change the count.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Count two fixed lengths
  2. Test a repetition rule
  3. Count strings by specifying which positions differ
  4. Modify the count if restrictions connect adjacent positions

Count two fixed lengths

An alphabet with symbols A, B, and C gives nine strings of length two and twenty-seven of length three when repetition is unrestricted. Those length sets are disjoint, giving thirty-six strings across them. This uses products and disjoint sums.

Test a repetition rule

If consecutive symbols must differ, a three-position string starts with three choices and then has two choices at each later position, yielding twelve possibilities.[1]

Count strings by specifying which positions differ

Over alphabet A, B and C, require a length-four string with exactly one A. There are four positions for A. Each of the other three positions independently admits B or C, giving \(4\cdot2^3=32\) strings. See multiplication of choices.

A at position 0: A___ with 8 completions
A at position 1: _A__ with 8 completions
A at position 2 or 3: another 16 completions
All four cases are disjoint

Modify the count if restrictions connect adjacent positions

Forbidding consecutive B symbols eliminates some completions inside each case. Independent position choices then require a more detailed state describing the previous letter. Verify a proposed formula against enumeration for short strings.

References

  1. Eric Lehman, F. Thomson Leighton and Albert R. Meyer, Mathematics for Computer Science ↩