Definition. Given a binary string s, denote its length as ∣s∣. For all i∈[∣s∣], the prefix of length i, denoted as s[1:i], is the binary string that consists of the first i bits of s.
Definition. Let S be the set of binary strings with n zeros and n ones, i.e.,
S≐{s:s∈{0,1}2n∧σ(s)=λ(s)}.
Of interest is the subset P⊂S that contains strings whose prefixes have more (or equal) number of 0 than 1:
P≐{s:σ(s[1:i])≥λ(s[1:i]),∀i∈[2n]}.
Theorem. The size of P, denoted as ∣P∣, equals the Catalan number Cn defined as
∣Cn∣=n+11(n2n).
Let S∖P be the set of strings that do not satisfy the requirement and define
T≐{s:s∈(0,1)2n∧σ(s)=n−1∧λ(s)=n+1}.
The proof relies on the following lemma.
Lemma. There is a bijection f between S∖P and T.
Before we prove it, we see how it gives Catalan number:
If s∈S∖P, then there exists some i∈[1,n−1], such that σ(s[1:i])<λ(s[1:i]).
Then we can select the smallest such i.
Note the i must be an odd number.
Hence we can write i=2j+1, σ(s[1:i])=j and λ(s[1:i])=j+1.
Further, as s∈S, we have σ(s)=λ(s)=n. Therefore,
σ(s[i+1:n])=n−jλ(s[i+1:n])=n−j−1
To construct an s′∈T from s, we can flipped every bit in s[i+1:n], i.e.,
s′=(s[1:i],s[i+1:n])
For sanity check, the number of zeros in s′ is j+n−j−1=n−1 and the number of ones is j+1+n−j=n+1.
It is easy to see that this is a injection.
⟵:
If s′∈T, then there must exist some i∈[1,n−1], such that σ(s′[1:i])<λ(s′[1:i]). Then we can select the smallest such i. Note the i must be an odd number. Hence we can write i=2j+1, σ(s′[1:i])=j and λ(s′[1:i])=j+1.
Further, as s′∈T, we have σ(s′)=n−1 and λ(s′)=n+1. Therefore,
σ(s′[i+1:n])=n−1−jλ(s′[i+1:n])=n+1−j−1=n−j
To construct an s∈S∖P from s′, we can flipped every bit in s′[i+1:n], i.e.,
s=(s′[1:i],s′[i+1:n])
For sanity check, the number of zeros in s is j+n−j=n and the number of ones is j+1+n−1−j=n.