Combinatorics · Lesson 5
Generating Unbordered Words
The GenU algorithm
The Nielsen recurrence tells us how many unbordered words there are, but not which ones. The GenU algorithm lists every unbordered word of length , exactly once.
The idea is to build words from both ends inward:
- Start with every two-letter word with (all such words are unbordered).
- Insert two middle symbols at a time, extending both ends.
- Never allow an insertion that would make the two halves equal — that is exactly what would create a border.
There are 6 unbordered binary words of length 4.
Generated by the GenU algorithm, growing each word from both ends: start with a two-letter
word whose letters differ, then insert two middle symbols — never allowing the two halves to become
equal.
Why this works
The only way the even-length extension becomes bordered is if the newly formed middle is itself a full word — which the algorithm checks before inserting.
Efficiency
Every recursive call in GenU produces at least one output word (or a subtree that does), so the total work is proportional to the number of generated words. Excluding the cost of printing each word, GenU runs in constant-amortized time.
Practice
Which words are unbordered?
Which of these words are unbordered? Select all that apply.
Which of these words are unbordered? Select all that apply.
Practice this topic →Every quiz from this lesson, at four difficulties.