Three bijections for marked walks

This post gives explicit bijections for the three marked-walk identities posed in item 3 of the original question. In all three cases, one side counts walks with marks that the other side moves or removes, and each cuts the walk at a position that can be found again by scanning for the first or last time some event happens, such as the first visit to a given height or the last time the walk reaches its maximum height. We will discuss the identities out of asked order, and in order of how much has to be recovered from the output, from a single hidden cut in Section 1 to an output with no mark at all in Section 3.

The same post, without the interactive diagrams, is also my answer on Math.StackExchange.

Throughout, we write 00 for an up-step (+1+1) and 11 for a down-step (−1-1). By a balanced walk we mean a walk that ends at height zero (though it is free to dip below zero along the way). Marks sit on the vertices of a walk: writing A∣BA\mid B means we have placed a mark at time ∣A∣|A|, which splits the walk in two. Marks at the endpoints are allowed, and they still split the walk in two (one piece being the empty walk). Similarly, two marks divide the walk into three pieces, and are allowed to coincide (in the coinciding case, we have the middle piece be the empty walk).

1. Marked returns and the convolution identity

Let e=N mod 2e = N \bmod 2, so that a walk of length NN ending at height ee is balanced when NN is even and ends one step above zero when NN is odd. We want to understand why the number of walks of length NN ending at height ee with a marked visit to height hh equals the number of walks of length NN ending at height 2h−e2h-e with a marked visit to height 00.

Moving a balanced piece to the front

In a target walk, the mark sits at height 00, so the part before the mark is a balanced walk of some even length 2i2i, counted by (2ii)\binom{2i}{i}. To produce such a walk from an input, we would like to find a balanced piece inside the input and move it to the front.

Write the input as A∣BA\mid B, so that AA runs from height 00 to the marked height hh and BB runs from hh to ee. Whenever AA visits height hh, the stretch of AA from that visit to the mark starts and ends at height hh. Every visit to hh therefore gives a candidate balanced piece (including the visit at the mark itself, whose piece is empty), and the construction has to choose one of them. Cutting AA at its first visit to hh, we write

A=FE,A = FE,

where FF runs from 00 to hh and reaches hh for the first time at its final vertex, and EE starts and ends at height hh. We write the walk as FE∣BFE \mid B, and then transform to E∣FBE \mid FB, moving EE to the front along with the mark.

After the mark, FF runs from 00 to hh, and BB would then bring the walk to ee, a net displacement of e−he-h for BB. However, the target walk must land at 2h−e2h-e, so after FF it must move by h−eh-e instead. We solve this problem by flipping the up and down steps of BB, that is, by taking its bitwise complement B‾\overline{B}. Thus, the final map is

FE∣B⟼E∣FB‾.\boxed{FE\mid B\longmapsto E\mid F\overline B.}

Since EE is balanced, the mark sits at height 00. After the mark, FF moves from 00 to hh and B‾\overline{B} moves by h−eh-e, so the output ends at h+(h−e)=2h−eh + (h-e) = 2h-e.

Recovering the cut

Suppose we are handed an output walk E∣RE\mid R ending at height d=2h−ed = 2h-e. The mark tells us where EE ends, and the endpoint tells us the original height, h=(d+e)/2h = (d+e)/2. What remains is to split RR back into FF and B‾\overline{B}. The walk RR starts at height 00 and may pass through height hh many times, and FF ends at one of these visits. This is why cutting AA at the first visit to hh was important, because now we can determine that FF ends at the first time RR reaches hh, and scanning RR forward from the mark will recover it. Writing R=FCR = FC at that first visit, the inverse returns FE∣C‾FE\mid\overline{C}, where C‾\overline{C} is the walk we get after flipping the up and down steps of CC.

E∣FC⟼FE∣C‾.\boxed{E\mid F C \longmapsto F E\mid \overline C.}

For an arbitrary target walk E∣RE\mid R ending at dd, this first visit to h=(d+e)/2h=(d+e)/2 always exists, because hh lies between 00 and dd (because d≡e(mod2)d \equiv e \pmod 2 with e∈{0,1}e \in \{0,1\}), and a walk with ±1\pm 1 steps cannot get from 00 to dd without passing through hh.

We can quickly verify that the reassembled object is a valid input and that the two maps undo each other. The prefix FEFE ends at height hh, and C‾\overline{C} has displacement −(d−h)=h−d=e−h-(d-h) = h-d = e-h, so FE∣C‾FE\mid\overline{C} ends at height h+(e−h)=eh + (e-h) = e, as an input must. Since EE is balanced and begins at height hh, the first visit of FEFE to hh is still the end of FF, so the forward map cuts FEFE at the same place and returns E∣F CE\mid F\,C, the walk we started with. Conversely, on an output E∣FB‾E\mid F\overline{B} of the forward map, the first-visit rule recovers the original FF and C=B‾C=\overline{B}, and hence the original input.

In the diagram below, dragging the mark to another visit to the same height leaves FF alone and changes only EE.

Connection to the convolution

If we re-index by kk (0≤k≤N0 \le k \le N) so that T(N,k)T(N,k) counts input walks marked at height h=k−⌊N/2⌋=k−(N−e)/2h = k - \lfloor N/2 \rfloor = k - (N-e)/2, then the output walk ends at height d=2k−Nd = 2k - N. When the zero mark in the output occurs at step 2i2i, there are (2ii)\binom{2i}{i} choices for the location of up-steps of the balanced prefix EE and (N−2ik−i)\binom{N-2i}{k-i} choices for the remaining N−2iN-2i steps (which must contain k−ik-i up-steps to reach 2k−N2k-N). Summing over ii gives

T(N,k)=∑i=0min⁡(k,N−k)(2ii)(N−2ik−i),T(N,k)=\sum_{i=0}^{\min(k,N-k)} \binom{2i}{i}\binom{N-2i}{k-i},

which is the convolution entry OEIS A204621.


2. Pairs of zero marks

Next, we want a bijection between balanced walks of length 2n2n carrying two ordered marks at height zero (which may coincide) and balanced walks of length 2n2n carrying a single mark at an arbitrary vertex. Since two zero marks split a balanced walk into three independent balanced walks of lengths 2a,2b,2c2a, 2b, 2c, this proves

(2n+1)(2nn)=∑a+b+c=n(2aa)(2bb)(2cc).(2n+1)\binom{2n}{n}= \sum_{a+b+c=n} \binom{2a}{a}\binom{2b}{b}\binom{2c}{c}.

Excursions

Write an input walk with two zero marks as L∣K∣RL\mid K\mid R, where LL, KK, and RR are balanced pieces. The output may carry only one mark, and both ends of KK have to be recovered from it. This is possible if we rearrange KK in a way that encodes the added information.

Let us rearrange KK into an excursion, a nonempty balanced walk that touches height zero only at its two endpoints. This is worth the trouble because, from any interior vertex of an excursion, the two endpoints are the nearest visits to height 0 on either side, so they give a natural way to turn a single mark back into two marks at height 0. Once KK is an excursion and the output mark is placed inside it, scanning outward from the mark recovers LL, the excursion, and RR.

The position of the mark within the excursion must also uniquely encode how KK was rearranged, so that the rearrangement can be undone. An excursion of length 2m2m has 2m−12m-1 interior vertices, so each excursion must arise from 2m−12m-1 choices of KK, one for each position of the mark.

Rotating the middle piece

Suppose KK is nonempty, say of length 2m>02m > 0, and that it starts with an up-step 00. (We return at the end of the section to the empty case and to the case where KK starts with a down-step 11, which is the same construction with all signs reversed.)

We set aside the initial up-step 00 of KK for now. It will come back as the final step. The word ww that remains has length 2m−12m-1 and net displacement −1-1. A cyclic permutation of ww cuts it into two pieces w=ABw = AB and swaps them to give BABA. There are 2m−12m-1 of them, one for each place to cut, since cutting at either end gives ww back.

We cut ww at its last highest point. Let that maximum height be zz, measured in KK. Since ww has lost the initial up-step, the cut sits at height z−1z-1 in ww, and the piece from there to the end of ww, at −1-1, has a net displacement of −z-z. Let us call this piece BB, and the piece before the cut AA, with a displacement z−1z-1, so that K=0ABK = 0AB (where AA may be empty). BB never goes back up to z−1z-1, because we cut at the last visit to the maximum. In ww, AA climbed from 00 and never rose above z−1z-1, but if we keep BB at its heights in ww, from z−1z-1 down to −1-1, then in BABA the piece AA starts where BB ends, at −1-1, so every height is one lower and AA never reaches z−1z-1 again either. Thus, if we move BB to start at 00, the walk BABA stays strictly below zero after its first vertex and ends at height (−z+(z−1))=−1(-z+(z-1))=-1, and the reserved up-step 00 climbs back to height 00. The walk BA0BA0 is a negative excursion, a walk that starts at height 00, ends at height 00, and is at a negative height everywhere in between.

Cutting at an earlier visit to the maximum will not work, as the cyclic permutation reaches the last visit at the same height. Cutting below the maximum fails too, since the cyclic permutation eventually passes the maximum. Even if the maximum only comes in the part moved from the front of ww, where every height is one unit lower, it is still at least as high as where we started. This is the cycle lemma: a word with net displacement −1-1 (m−1m-1 up-steps and mm down-steps) has exactly one cyclic permutation whose nonempty prefixes all lie strictly below zero.

We place the output mark between BB and AA, writing B∣A0B\mid A0, so the mark records where ww was cut. The 2m−12m-1 possible cuts correspond to the 2m−12m-1 interior vertices of the excursion, which is the count required above. Since BB ends at height −z-z, the mark sits at height −z<0-z < 0.

With the outer pieces restored, the map is

L∣0AB∣R⟼LB∣A0R.\boxed{L\mid 0AB\mid R\longmapsto LB\mid A0R.}

For example, consider ∣001011∣\mid001011\mid, with LL and RR empty. The walk 001011001011 reaches its maximum height z=2z=2 at steps 22 and 44. Cutting at the last of these (step 44) gives 0A=00100A = 0010, so A=010A = 010 and B=11B = 11. The map sends

∣0 (010) (11)∣⟼11∣0100.\mid0\,(010)\,(11)\mid \longmapsto 11\mid0100.
The middle piece 001011 is cut at its last maximum into 0, A = 010, and B = 11. Rearranging these pieces gives the negative excursion 110100, marked after B.
The middle piece 001011 is cut at its last maximum into 0, A = 010, and B = 11. Rearranging these pieces gives the negative excursion 110100, marked after B.

Here z=2z=2. Moving BB to the front shifts it down by 22, while placing AA after BB shifts AA down by 33. The single mark sits at their join at height −2-2, and the initial up-step becomes the final return to zero.

Inverting the excursion map

Suppose the single mark in a balanced walk sits at some negative height −z<0-z < 0. Scanning outward from the mark, the nearest vertices at height zero bound a negative excursion, and the last step of that excursion is an up-step 00. The mark and this final step split the excursion uniquely as B∣A0B\mid A0, and the inverse map is

LB∣A0R⟼L∣0AB∣R.\boxed{LB\mid A0R\longmapsto L\mid 0AB\mid R.}

To verify that this works for every marked negative excursion B∣A0B\mid A0 with the mark at height −z<0-z < 0, we trace the heights of the reassembled walk 0AB0AB. The initial 00 reaches height 11. The piece AA, which ran from −z-z to −1-1 while staying at or below −1-1, is shifted up by z+1z+1, so 0A0A stays at or below zz and ends at height zz. Then BB, which ran from 00 to −z-z and stayed strictly below 00 after its start, is appended at height zz, so it stays strictly below zz after the join and ends at 00. Consequently 0A0A ends at the last maximum of 0AB0AB, and the forward map cuts 0AB0AB at the same place.

When KK starts with a down-step 11, the same construction with signs reversed cuts K=1ABK = 1AB at its last minimum and maps

L∣1AB∣R⟼LB∣A1R,\boxed{L\mid1AB\mid R\longmapsto LB\mid A1R,}

which produces a positive excursion with its mark at height +z>0+z > 0. For the reverse map, the single mark lies at a positive height and the original walk can be found similarly. In both nonempty cases, the rearrangement sAB→BAssAB \to BAs is the same: a cyclic permutation of w=ABw = AB, with the set-aside first step ss moved to the end.

That leaves the case where the two zero marks coincide, so that KK is the empty walk. The forward map merges them into a single mark at height 00, sending L∣ ∣R↦L∣RL\mid\,\mid R \mapsto L\mid R. A mark at height 00 can only come from this case, because the nonempty cases put the mark at −z<0-z < 0 or +z>0+z > 0. So the inverse splits a mark at height 00 back into two coincident zero marks.

In the diagram below, the single output mark lands at height 00 only when the two zero marks are dragged together.

Bonus: The Return of the Catalans

The count from the start of this section becomes an identity if we restrict the construction to a single middle piece KK of length 2m>02m > 0 starting with up-step 00. The construction then gives a bijection between balanced walks of length 2m2m starting with up-step 00, of which there are (2m−1m−1)\binom{2m-1}{m-1}, and negative excursions of length 2m2m with one interior mark. Reflecting a negative excursion of length 2m2m (about the x-axis) and stripping its first and last steps produces a Dyck path of length 2m−22m-2, so there are Cm−1=1m(2m−2m−1)C_{m-1} = \frac{1}{m}\binom{2m-2}{m-1} such excursions, each with 2m−12m-1 interior vertices available to mark. Equating the two counts gives the classical identity

(2m−1m−1)=(2m−1)Cm−1.\binom{2m-1}{m-1}=(2m-1)C_{m-1}.

3. Marks at a fixed height

For the last identity, we want a bijection between balanced walks of length 2n2n with a marked visit to a fixed height kk, and binary strings of length 2n+12n+1 containing at most n−∣k∣n-|k| ones. Such a bijection gives a combinatorial proof that

#{balanced walks with a marked visit to k}=∑r=0n−∣k∣(2n+1r).\#\{\text{balanced walks with a marked visit to }k\} =\sum_{r=0}^{n-|k|}\binom{2n+1}{r}.

We assume ∣k∣≤n|k|\le n, since otherwise both sets are empty.

Inserting a step at the mark

In this identity the output is an unmarked string, one step longer than the input, so the extra step can be inserted at the mark. An answer by natalia to an earlier question proves this sum as its equation (2) and credits GChromodynamics for help with the proof. That proof inserts a step after the marked visit to kk and reflects every step after it, which turns the marked visits to kk, minus the marked visits to k+1k+1, into walks of length 2n+12n+1 ending at height 2k+12k+1; the sum then follows by adding up these differences. Here we are aiming for a single bijection, so the inserted step has to be recognizable as the first or last occurrence of some event, like the first visit to hh in Section 1 or the last maximum in Section 2.

Suppose first that k≥0k\ge0, and write the marked walk as u∣vu\mid v, so that uu ends at height kk. If we insert an up-step 00 at the mark, the new step goes from height kk to k+1k+1. For the inverse to be able to find it, we want it to be the last up-step from kk to k+1k+1 in the whole walk. That will always be true if the walk never comes back down to height kk afterwards, but the suffix vv does not satisfy this condition as it stands, since it has to get from height kk back to 00. So we need to modify vv into a walk v′v' that stays at or above its starting height, in a way that can be undone.

As a running example, take n=6n=6, k=1k=1, and the walk 01001∣011011001001\mid0110110.

The simplest change to vv would be to reflect all of it, swapping every 00 and 11. This is the idea of the proof cited above, and it sends every marked walk to a string ending at height 2k+12k+1, that is, with exactly n−kn-k ones. But there are only (2n+1n−k)\binom{2n+1}{n-k} such strings, far fewer than the marked walks. For n=6n=6 and k=1k=1, the values of our running example, there are (135)=1287\binom{13}{5}=1287 strings of length 1313 with five ones, but ∑r=05(13r)=2380\sum_{r=0}^{5}\binom{13}{r}=2380 marked walks, nearly twice as many. Reflection must therefore send different marked walks to the same string, and the inverse could not tell them apart. A bijection onto strings with every number of ones up to n−kn-k has to keep a record, and the number of ones can be that record if we choose which steps to flip in a way the inverse can recognize.

Lifting the suffix

Which steps do we need to flip? Read vv as a string of parentheses, with each up-step 00 as "(" and each down-step 11 as ")", and match each 11 with the most recent unmatched 00 before it. A matched 00 and 11, together with everything between them, return to the height where they started without going below it, so no matched part of vv takes the walk to a new low. The only steps that can are the unmatched down-steps: each lands at a height the walk has not visited before, so these are its record-low down-steps. If we turn every unmatched 11 into a 00 and leave the rest alone, nothing pulls the walk down any more, and it stays at or above its starting height. The inverse can run the same matching to find these steps again.

On our example suffix v=0110110v = 0110110, scanning from left to right, the matching gives

0110110=01⏟matched  1  01⏟matched  1  0,0110110= \underbrace{01}_{\text{matched}}\;\boxed{1}\; \underbrace{01}_{\text{matched}}\;\boxed{1}\;\boxed{0},

where the boxed bits are left unmatched. In general, any unmatched 00 preceding an unmatched 11 would have been matched with it, so the unmatched bits always form a subsequence of the form

1a0b1^a0^b

(in our example, 110110, so a=2a=2 and b=1b=1). Moreover, no matched pair can straddle an unmatched bit: an enclosed 00 would have to be matched before the outer pair could close, and an enclosed 11 would have found the outer opening 00 available. So the segments before, between, and after the unmatched bits are balanced detours, each staying at or above its own starting height.

We now flip those aa unmatched ones to zeros and leave every matched bit and every unmatched zero as it was, making the unmatched subsequence 0a+b0^{a+b}. Call the result v′v'. The balanced detours are now joined only by up-steps, so v′v' never dips below its starting height. (Up to our reversed bit convention, this is the Catalan factorization of Eğecioğlu and King, §3.)

Inserting the up-step 00 at the mark before v′v', the full forward map is

u∣v⟼u 0 v′.\boxed{u\mid v\longmapsto u\,0\,v'.}

In our running example, flipping the two boxed ones in vv gives v′=0100100v'=0100100, so

01001∣0110110⟼(01001) 0 (0100100).01001\mid0110110\longmapsto(01001)\,0\,(0100100).
The suffix 0110110 and its transformed suffix 0100100 at the same scale. The two flipped steps are highlighted, and balanced detours are shaded.
The suffix 0110110 and its transformed suffix 0100100 at the same scale. The two flipped steps are highlighted, and balanced detours are shaded.

Both panels plot the suffix starting at height zero. The shaded balanced detours keep their shapes and horizontal positions, while the two highlighted down-steps flip into up-steps.

Since uu ends at height kk and the whole walk uvuv is balanced, the suffix vv has net displacement −k-k, which means a−b=ka-b=k, and in particular a≥ka \ge k. The input has nn ones, and we flipped aa of them, so the output has n−a≤n−kn-a\le n-k ones. The number of ones in the output thus records how many steps were flipped, which is why the target set contains strings with every number of ones up to n−kn-k. Finally, the inserted up-step at the mark moves from kk to k+1k+1, and v′v' stays at or above k+1k+1 after it, so the end of uu is the last time the output visits height kk.

Inverting the map

Now suppose we are given k≥0k \ge 0 and a binary string qq of length 2n+12n+1 with r≤n−kr \le n-k ones. The forward map reduced the number of ones from nn to n−an-a, so the number of bits to flip back is

a=n−r.a=n-r.

Since r≤n−kr \le n-k, we have a≥ka \ge k, so qq ends at height

(2n+1−r)−r=2n+1−2r=2a+1>k.(2n+1-r) - r = 2n+1-2r = 2a+1 > k.

In our example output, q=0100100100100q = 0100100100100, there are r=4r=4 ones, so a=6−4=2a = 6-4 = 2 unmatched zeros must be flipped back into ones.

To locate the cut, we find the last time qq visits height kk and factor qq there as q=u 0 v′q=u\,0\,v'. Since qq ends above kk, the step after that visit has to be an up-step to k+1k+1, and it is the step the forward map inserted. In our example, qq is last at height 11 after step 55, which recovers u=01001u=01001 and v′=0100100v'=0100100.

To decide which zeros of v′v' to flip back, we run parenthesis matching on v′v'. In the original suffix vv, the unmatched bits had the form 1a0b1^a0^b, with all aa ones before all bb zeros, and flipping the ones turned this subsequence into 0a+b0^{a+b}. The flipped bits are therefore the first aa unmatched zeros of v′v'. The inverse turns those back into ones, and replaces the 00 between uu and v′v' with the mark. On our example suffix, matching gives

v′=01⏟matched  0  01⏟matched  0  0,v'=\underbrace{01}_{\text{matched}}\;\boxed{0}\; \underbrace{01}_{\text{matched}}\;\boxed{0}\;\boxed{0},

and flipping the first two boxed zeros restores v=0110110v=0110110 and the marked walk 01001∣011011001001\mid0110110.

We still need to check that this inverse is defined on every string qq with r≤n−kr \le n-k ones. Since qq starts at 0≤k0 \le k and ends above kk, it visits height kk, and after its last visit the suffix v′v' stays at or above its starting height k+1k+1. Every 11 in v′v' is therefore matched by a 00 in v′v', so v′v' has no unmatched ones, and the number of unmatched zeros in v′v' equals its net displacement:

(2a+1)−(k+1)=2a−k≥a.(2a+1)-(k+1)=2a-k\ge a.

So v′v' always has at least aa unmatched zeros available to flip. Flipping the first aa of them changes the unmatched subsequence from 02a−k0^{2a-k} to 1a0a−k1^a0^{a-k}, which gives a suffix vv of net displacement −k-k that brings the walk from height kk back to 00. Because the balanced detours between unmatched bits are never touched, matching the bits of vv matches the same bits as matching the bits of v′v', and its unmatched ones are the aa bits that the inverse flipped. The forward map therefore flips those bits back and reinserts the step that the inverse removed, returning qq.

Finally, if k<0k<0, we complement every bit of the input walk, which reflects it vertically so that the mark sits at height ∣k∣>0|k| > 0. We then apply the construction for ∣k∣|k|, and the inverse complements the recovered walk at the end. (When n=k=0n=k=0, the empty marked walk maps to 00.)

In the diagram below, wherever the mark is dragged, the inserted up-step is the last step from kk to k+1k+1 in the output.

Construction notes

Before landing on the cyclic-permutation construction in Section 2, my initial proof composed the bijection from Section 1 with two operations from Eğecioğlu and King, §§2–3 (splitting at the last zero and converting a non-returning walk into a balanced walk). That route worked, but inverting it required chasing down several intermediate cuts. Asking whether a single interior mark could encode both endpoints of KK at once led to excursions and the cycle lemma.

Acknowledgements

Thank you natalia for bringing my attention to these questions! Thank you Mike Earnest for your linked answer, which led me to discover the ideas behind Catalan Factorizations!

References

Ömer Eğecioğlu and Alastair King, Random Walks and Catalan Factorization, Congressus Numerantium 138 (1999), 129–140.

Nachum Dershowitz and Shmuel Zaks, The Cycle Lemma and Some Applications, European Journal of Combinatorics 11 (1990), 35–40, §1.