Combinatorics · Lesson 4

Counting Unbordered Words

The counting problem

Let Uk(n) be the set of unbordered words of length n over a k-letter alphabet, and write uk(n)=|Uk(n)|.

Every word is either bordered or unbordered, but not both, so:

uk(n)+bk(n)=kn

The Nielsen recurrence

The key fact: if w=uv is split into two halves, then inserting a symbol into the middle preserves “unbordered” status in exactly the ways captured below.

Intuition for the odd case: an unbordered word of length n−1 stays unbordered when a symbol is inserted in the middle, and every length-n unbordered word arises exactly this way.

The even case subtracts exactly the words that would gain a border by that middle insertion: those of the form zz where z is an unbordered word of length n/2.

Exploring the recurrence

Use the table below to see how uk(n) and bk(n) grow:

Alphabet size k: Length n:
Unbordered and bordered word counts uk(n) and bk(n)
nu2(n)b2(n)2n
0101
1202
2224
3448
461016
5122032
6204464

u2(6) + b2(6) = 64 — every length-6 word over a 2-letter alphabet is either bordered or unbordered.

For example, u2(4): the binary unbordered words of length 4 are 0001, 0011, 0111, 1000, 1100, 1110 — six of them.

A limiting frequency

It can be shown that uk(n)/kn converges as n→∞. For binary words the limit is about 0.267786 — roughly a quarter of all binary words are unbordered.

Practice

Compute the count

How many unbordered words of length 3 are there over a 2-letter alphabet?

How many unbordered words of length 6 are there over a 3-letter alphabet?

Practice this topic →Every quiz from this lesson, at four difficulties.

References