Foundations · Lesson 3
Borders
Definition
Intuition: the same nonempty string appears at both the beginning and the end of the word.
A border must be nonempty (so never counts) and proper (strictly shorter than , so the whole word never counts).
For 010010, the borders are 0 and 010 — each appears at both ends:
Yes — 010 is both a prefix and a suffix, so it is a border.
A non-example
For 001001, length is not a border: the prefix of length 2 is 00, but the suffix of length 2 is 01. The prefix and suffix differ:
No — 00 is not a border: the prefix and suffix differ.
Bordered and unbordered words
The empty word and every one-letter word are unbordered: a one-letter word has no nonempty proper factor at all.
For example, aaaa is bordered (its borders are a, aa, aaa), while abcde is unbordered.
Why borders matter: packet markers
Imagine a stream of bits being sent from one computer to another. The stream is split into packets, and the receiver needs to know where each packet begins and ends. So we insert a marker, say the word 010, between every packet.
The trouble is that two occurrences of 010 can overlap. In the stream
010 | 10 = 01 | 010
the packet following the marker begins with 10, and the packet before the marker ends with 01. Both produce the same bit string 01010, so the receiver cannot tell where the packet boundary is: is it 010 | 10 or 01 | 010?
The shared symbol is a border of the marker. More generally, any overlap between two distinct occurrences of a marker is simultaneously a suffix of the first occurrence and a prefix of the next — exactly a border of the marker. An unbordered marker therefore can never overlap another occurrence of itself, which is why unbordered words are studied in digital communications. This same border information later lets pattern-matching algorithms reuse comparisons: after a partial match fails, a border tells us which part of the match is still useful.
Longest and shortest border
If a word has borders, the longest border is the border of greatest length, and the shortest border the border of least length.
For abababa, the borders are a, aba, and ababa:
- longest border:
ababa - shortest border:
a
Note that ab is not a border: its suffix counterpart of length 2 is ba, not ab.
Practice
Identify all borders
Find all proper borders of 0110.
Is it unbordered?
Is 0101 unbordered?
Longest and shortest border
What is the longest border of 1011?
What is the shortest border of 010?
Construct an unbordered word
Construct a binary word of length 3 that is unbordered.
Practice this topic →Every quiz from this lesson, at four difficulties.
References
- Substring (including borders) — Wikipedia
- Combinatorics on words — Wikipedia
- Lothaire, Combinatorics on Words, Cambridge University Press, 1997