GATE / CS ARCHIVE

GATE CSE 1991 / QUESTION 16(a)

Balanced binary prefixes and Catalan numbers

Discrete Mathematics · Combinatorics & Counting · Full GATE CSE 1991 paper

GATE 1991, Q16(a) 5 marks · Descriptive
Report issue

Combinatorics & Counting

Question 16(a), GATE 1991: How many length-2n binary strings have n zeros and n ones and every prefix contains at least as many zeros as ones?
Tap to enlarge
Answer & solution

Answer: C_n = binom(2n,n) − binom(2n,n−1) = binom(2n,n)/(n+1). (no official key was published)

Interpret a zero as a +1 step and a one as a −1 step. A balanced string gives a walk from height 0 to height 0 in 2n steps. The prefix restriction asks that the height never become negative. There are binom(2n,n) balanced strings before imposing the restriction.

Count the bad strings by reflection. A bad walk has a first step reaching height −1. Swap zeros and ones in the segment from the beginning through that first visit. Originally that segment has one more one than zero; after the swap it has one more zero than one. Consequently the transformed entire string has n+1 zeros and n−1 ones and ends at height +2.

Conversely, any string with n+1 zeros and n−1 ones must first reach height +1. Reflect its prefix through that first visit. The resulting balanced walk first reaches −1 there, so it is bad. These two operations invert each other, establishing a bijection. The number of bad strings is therefore binom(2n,n−1), choosing the positions of its n−1 ones after reflection.

Subtracting gives binom(2n,n)−binom(2n,n−1). Since binom(2n,n−1)=n·binom(2n,n)/(n+1), the result is Cn=binom(2n,n)/(n+1), the nth Catalan number. For n=0, the empty string contributes one; for n=2, the valid strings are 0011 and 0101, agreeing with C2=2.

Original paper, page 8