On the Sweep Map for $\vec{k}$-Dyck Paths

Garsia and Xin gave a linear algorithm for inverting the sweep map for Fuss rational Dyck paths in $D_{m,n}$ where $m=kn\pm 1$. They introduced an intermediate family $\mathcal{T}_n^k$ of certain standard Young tableau. Then inverting the sweep map is done by a simple walking algorithm on a $T\in \mathcal{T}_n^k$. We find their idea naturally extends for $\mathbf{k}^\pm$-Dyck paths, and also for $\mathbf{k}$-Dyck paths (reducing to $k$-Dyck paths for the equal parameter case). The intermediate object becomes a similar type of tableau in $\mathcal{T}_\mathbf{k}$ of different column lengths. This approach is independent of the Thomas-Williams algorithm for inverting the general modular sweep map.


Introduction
1.1. The Sweep map. The sweep map is a mysterious simple sorting algorithm that is also invertible. The best way to introduce the sweep map is by using rational Dyck paths, because it already raises complicated enough problems and it has natural generalizations. We will use three models, each having their own advantages.
Model 1: Classical path model. For a pair of positive integers (m, n), the so called rational (m, n)-Dyck paths are paths proceed by North and East unit steps from (0, 0) to (m, n) remaining always above the main diagonal (of slope n/m). A (kn, n)-Dyck path is also called a k-Dyck path of length n. Each vertex is assigned a rank as follows. We start by assigning 0 to (0, 0). This done we add an m as we go North and subtract an n as we go East. Figure 1 illustrates an example of an (12, 4)-Dyck path, or a 3-Dyck path of length 4. The sweep map is a bijection of the family D m,n of (m, n)-Dyck paths onto itself. The construction of the sweep map is deceptively simple. Geometrically in model 1, we sweep a path D ∈ D m,n by letting lines of slope n/m+ , where > 0 is sufficiently small, move from right to left, and draw a North step when we sweep the South end of a North step of D and draw an East step when we sweep the West end of an East step of D. The resulting path will be denoted by D = Φ(D) and can be shown to be in D m,n . For instance, Figure 2 illustrates the sweep map image of the Dyck path D in our running example.
Model 2: Word model. The SW-word SW(D) = σ 1 σ 2 · · · σ m+n is a natural encoding of D, where σ i is either an S or a W depending on whether the i-th vertex of D is a South end (of a North step) or a West end (of an East step). The rank is then associated to each letter of SW(D) by assigning r 1 = 0 to the first letter σ 1 = S and for 1 ≤ i ≤ m + n − 1, recursively assigning r i+1 to be either r i +m if the i-th letter σ i = S, or r i −n if otherwise σ i = W . We can then form the two line array SW(D) r(D) . For instance for the path D in Model 3: Visual path model. We can rotate and stretch the picture in model 1 so that the diagonal line becomes the horizontal axis. Then rational (m, n)-Dyck paths are paths from (0, 0) to (m + n, 0), with up steps S = (1, m) and down steps W = (1, −n), that stay above the horizontal axis. It is clear that the ranks are just the levels (or y-coordinates). The visualization of the ranks in this model allows us to have better understanding of many results. See [4,5]. See [1,3,7,9,10] for further references and related results.
The invertibility problem is to reconstruct D from the sole knowledge of SW(D).
The sweep map is an active subject in the recent decades. Variations and extensions have been found, and some classical bijections turn out to be the disguised version of the sweep map. See [2] for detailed information and references. One major problem in this subject is the invertibility of the sweep map. The bijectivity has been shown in a variety of special cases including the Fuss case when m = kn±1 which is proved in [10], [8]and [6]. The invertibility of the sweep map, even for rational Dyck paths, remained open for over ten years. Surprisingly, a general result proving the invertibility of a class of sweep maps that were listed in [2], was recently given by Thomas-Williams in [11]. Based on the idea of Thomas and Williams, Garsia and Xin [5] gave a geometric construction for inverting the sweep on (m, n)-rational Dyck paths. These algorithms are nice iteration algorithms, but are not linear: the number of iterations is measured by the sum of the ranks of D.
By using a completely different approach, Garsia and Xin find a O(m+n) algorithm for inverting sweep map on (m, n)-Dyck paths in the Fuss case m = kn ± 1. This raises the following problem.
Problem: Is there a linear algorithm to invert the sweep map, at least for a more general class of paths?
We find positive answer for k + , k − , and k-Dyck paths by extending Garsia-Xin's idea.
1.2. The notation of general Dyck paths. We start by introducing general Dyck paths using model 3.
General Dyck paths are two dimensional lattice paths from (0, 0) to (m + n, 0) that never go below the horizonal axis. We use vectors u = (u 1 , . . . , u n ) and d = (d 1 , . . . , d m ) to specify the up steps and down steps, so that D u,−d is the set of general Dyck paths with up steps (1, u i ), 1 ≤ i ≤ n from left to right, and down steps (1, −d j ), 1 ≤ j ≤ m from left to right. Clearly the total length of up steps |u| = u 1 + u 2 + · · · + u n is equal to the total length of down steps |d| = d 1 + d 2 + · · · + d m . When each d i = 1, we use the short hand notation D u = D u,−1 |u| , where 1 a consists of a 1's. Here we usually restrict u i and d j to be positive integers, but sometimes allowing rational numbers is convenient.
A general Dyck path D may be encoded as D = (a 1 , a 2 , . . . , a m+n ) with each entry either u i or −d j . The rank sequence r(D) = (0 = r 1 , r 2 , . . . , r m+n ) of D is defined as the partial sums r i = a 1 + a 2 + · · · + a i−1 ≥ 0, called starting rank (or level) of the i-th step. Geometrically, r i is just the level or y-coordinate of the starting point of the i-th step. The SW-word of D is SW(D) = σ 1 σ 2 · · · σ m+n where σ i = S a i if a i > 0 and σ i = W −a i if a i < 0 (with W 1 = W ). The sweep map D of D is obtained by reading its steps by their starting levels from bottom to top, and from right to left in the same level. This corresponds to sweeping the starting points of the steps from bottom to top using a line of slope for sufficiently small > 0.   (1) D 1n is the set of classical Dyck paths in the n × n square (rotated version).
(3) D k1n is just D kn,n , the set of k-Dyck paths of length n. (Their rank sequences differed by a factor n).
In what follows, k = k = (k 1 , k 2 , . . . , k n ) is always a vector of n positive integers. We will focus on k-Dyck paths in D k , i.e., general Dyck paths whose up steps are of lengths k 1 , . . . , k n from left to right, and whose down steps are all of length 1. We will also consider k + -Dyck paths in D k + and k − -Dyck paths in D k − , where k ± = k ± 1 n 1 n . These are natural extension of the Fuss case rational Dyck paths: k-Dyck paths are just k1 n -Dyck paths; Fuss case (kn ± 1, n)-Dyck paths are easily seen to be equivalent to k ± -Dyck paths.
The sweep map of a k-Dyck path is usually a k -Dyck path where k is obtained from k by permuting its entries. Denote by K the set of all such k and by D K the union of D k for all such k . We also use similar notation for K ± and D K ± .
Theorem 1.2. The sweep maps define bijections from D K + , D K − , and D K to themselves.
It is known but nontrivial that the sweep map takes a Dyck path to another Dyck path (see, e.g., [5] for a proof), so the proof of the theorem boils down to construct the inverse image D from a given Dyck path D.
The three sets D k , D k + , and D k − are closely related as follows. For D ∈ D k , let SW(D + ) be obtained from SW(D) by adding a W at the end and changing every S a to S a+1/n . Similarly let SW(D − ) be obtained from SW(D) by removing the final letter W and changing every S a to S a−1/n . It is clear that the map D → D + gives a bijection from D k to D k + . However, the map D → D − is a little different: it is a bijection from D • k to D k + , where D • k consists of paths D ∈ D k whose rank sequence r(D) has only one 0 at r 1 . Figure 4 illustrates the idea: Though the paths D + ∈ D k + and D ∈ D k have almost identical pictures, their sweep map inverse images D + ∈ D k + and D ∈ D k may be very different, due to the different sweep order. Therefore, their inverting algorithma are also very different.  1.3. The Filling algorithm and the k tableaux. In the Fuss case when m = kn + 1, a linear algorithm to invert the sweep map was discovered by Garsia and Xin in [6]. The algorithm relies on an intermediate family T k n of standard Young tableaux. The family T k n consists of n × (k + 1) arrays with entries 1, 2, . . . , kn + n, column increasing from top to bottom and row increasing from left to right, with the additional property that for any pair of entries a < d with d directly below a, the entries between a and d form a horizontal strip. That is, any pair of entries b, c with a < b < c < d never appear in the same column. The standard Young tableau T (D) constructed from the SW word of a path D encodes so much information about D. This allows us to invert the sweep map in the simplest possible way.
We find Garsia-Xin's construction naturally extends for k + -Dyck paths. The intermediate family T k n becomes the family T k , where the only difference is that tableau T ∈ T k has k i + 1 entries in the i-th column. The Filling Algorithm [6] is adapted in our case as follows, where the major change is the definition of active.
(1) Start by placing a 1 in the top row and the first column.
(2) If the second letter in SW(D) is an S * we put a 2 on the top of the second column.
(3) If the second letter in SW(D) is a W we place 2 below the 1. (4) At any stage the entry at the bottom of the i-th column but not in row k i + 1 will be called active. (5) Having placed 1, 2, · · · i − 1, we place i immediately below the smallest active entry if the i th letter in SW(D) is a W , otherwise we place i at the top of the first empty column. (6) We carry this out recursively until 1, 2, . . . , n + |k| have all been placed.
We will denote by t(T ) = (t 1 , . . . , t n ) the top row entries of T from left to right, and similarly by b(T ) = (b 1 , . . . , b n ) the bottom entries. Note that the former is always increasing, but the latter is not. See Figure 5 for an example. Lemma 1.4. A sequence (t 1 , . . . , t n ) is the top row entries t(T ) for some T ∈ T k if and only if t i ≤ k 1 + · · · + k i−1 + i holds for all i. Theorem 1.5. The Filling algorithm defines a bijection from D k to T k .

1.4.
Walking algorithm for k ± -Dyck paths. The walking algorithm for inverting the sweep map on D kn±1,n naturally extends to that of k ± -Dyck paths. To state our results, we need to modify some notations. For T ∈ T k , let T + be obtained from T by adding n + |k| + 1 below the entry n + |k|. Let T + k = {T + : T ∈ T k }. The bottom entry of the i-th column of T + refers to the (k i + 1)-st entry for all i including the column with the added entry n + |k| + 1.
(1) Write in bold all the entries in T + that are by 1 more than a bottom row entry.
(2) Go to 1 and write 1. Once the permutation σ(D + ) is obtained, the SW-word SW D + of the inverse image D + is easy to construct: we write one letter at a time by placing above each entry of σ(D + ) an S k + i if that entry is t i and a W if that entry is not in row 1. This done we can simply draw D + by reading the sequence of letters of SW D + . Note that we will also use this construction for σ(D − ) and σ(D) in a similar way. Theorem 1.7. For a Dyck path D + ∈ D k + , the permutation σ(D + ) that rearranges the letters of SW(D + ) in the order that gives the SW word of D + , is obtained by the Walking Algorithm + (Algorithm 1.6).
The proof is almost the same, so we only sketch the idea and point out the difference. Suppose b i = min(b(T )), i.e., the smallest bottom entry is in the i-th column. Then this column has no bold faced entry. (In T k n , this i is always 1.) Removing column i results in a tableau T + , which still satisfies the abcd condition. Then Walking Algorithm + applies to T + to give σ(D + ) (regard the entries as contiguous just like the Fuss case). The similarity between σ(D + ) and σ(D + ) can be used to give the proof. See Figure 6 for an example.
The situation for D k − is similar. Recall that D − ∈ D k − only when D ∈ D • k , i.e., the rank sequence r(D) has only one 0 at r 1 = 0. It is not hard to see that the filling algorithm takes such D to    The idea of the proof is similar to that of the k + -case. We only point out the difference. Suppose b i = min(b(T )), i.e., the smallest bottom entry is in the i-th column. (In T k n , this i is always 1.) Removing column i results in a tableau T − , which still satisfies the abcd condition. Then Walking Algorithm − applies to T − to give σ(D − ) (regard the entries as contiguous just like the Fuss case). The similarity between σ(D − ) and σ(D − ) can be used to give the proof. It is possible that column i has a bold faced entry. Then this bold faced entry must be the bottom entry b i : i) the smallest bold faced entry b i − 1 is not in this column; ii) b i is bold faced only when b i = b j − 1 for some j. This case also cause no trouble. See Figure 7 for an example.
1.5. The walking algorithm for k-Dyck paths. After extending Garsia-Xin's idea for k ± -Dyck paths, one might think the inverting algorithm will be similar for k-Dyck paths. It turns out that the situation is quit different.
The new walking algorithm not only relies on the intermediate tableau T = T (D) ∈ T k , but also on the rank tableau R(D) constructed from T .
It is convenient to call numbers in T indices. We will use a ranking algorithm to construct the rank tableau R(D) of T . For clarity, we start with the empty tableau of the shape of T , and successively assign each index a rank. By assigning index A a rank r, we mean to fill r into the box in R(D) corresponding to index A in T .  (1) Successively assign 0, 1, 2, ..., k 1 to the first column indices of T from top to bottom; (2) For i from 2 to n, if the top index of the i-th column is A + 1, and the rank of index A is a, then assign the index A + 1 rank a. Moreover, the ranks in the i-th column are successively a, a + 1, . . . , a + k i from top to bottom.
See Figure 8 for an example of the Filling algorithm. Observe that the indices are distinct, but the ranks are not. The largest rank r (entry) is the rank r with the largest index. For instance in Figure 8, the rank 2 entries have indices 5, 6, so the largest rank 2 entry is the rank 2 with index 6, whose box is located in row 3 column 2. Similarly, the smallest rank 2 entry is the rank 2 with index 5, whose box is located in row 3 column 1.
We find a way to obtain the permutation σ(D) directly from T (D) and R(D) as follows. (1) In R(D), go to the largest rank 0 entry. Mark this rank and write down its index; (2) Repeat the following steps until no unmarked rank can be selected.
(a) If we are in row 1, then go to the bottom row in the same column. If the rank there is r then go to the largest unmarked rank r. Mark this rank and write down its index; (b) If we are not in row 1, then go up one box. If the rank there is r then go to the largest unmarked rank r. Mark this rank and write down its index.
Theorem 1.12. For a Dyck path D ∈ D k , the permutation σ(D) that rearranges the letters of SW(D) in the order that gives the SW word of D, is obtained by the Walking Algorithm.
Let us apply Walking Algorithm (Algorithm 1.11) to the index-rank tableau (T, R) in Figure 8. The permutation σ(D) is given on the top row. From it one easily produce the middle SW(D), whose rank sequence is given in the third row for comparison. Now we clearly see that the ranks of D are exactly the ranks in R(D).  0 4 3 8 7 6 5 4 7 6 5 4 3 2 The paper is organized as follows. In this introduction, we have introduced the main concepts, as well as our main results, especially Theorems 1.12 which give linear inverting algorithms for k-Dyck paths. Section 2 includes the basic facts of the sweep map and the proof of Theorem 1.12, but leave the proof of Lemma 2.4 in Section 3. Lemma 2.4 says that our Walking algorithm produces a permutation σ(D) of the desired length. To prove this lemma, we give two different approachs in Section 3.

Some basic auxiliary facts about the sweep map
There are a number of auxiliary properties of the sweep map in k-Dyck paths that need to be established to prove our basic results.  Proof. Assume to the contrary that i with 2 ≤ i ≤ n is the smallest such that the top index of the i-th column, say A > 1, cannot be assigned a rank. This only happens when the index A − 1 is not assigned a rank yet. But then A − 1 must not belong to the first i − 1 columns, contradicting the Filling Algorithm. Lemma 2.3. Let D ∈ D k be a k-Dyck path with rank tableau R(D). Then the ranks are weakly increasing according to their indices in T (D). In other words, if indices 1, 2, . . . , n + |k| are assigned ranks r 1 , r 2 , r 3 , . . . , r n+|k| , then 0 = r 1 ≤ r 2 ≤ r 3 ≤ . . . ≤ r |k|+n . More precisely, r i − r i−1 is either 0 or 1 for each 2 ≤ i ≤ |k| + n.

Proof. We prove by induction on i.
For the base case i = 2, we need to consider the following two cases by using the Filling algorithm 1.3.
There are three cases as follows.
Case 1: If index i + 1 is in row 1, then r i+1 = r i ; Case 2: If index i + 1 is placed under index i, then r i+1 = r i + 1; Case 3: Otherwise, the index i + 1 is not in row 1 and is not placed under index i. We use the fact that if the index j with j ≥ 2 is in row 1, then r j = r j−1 . Let i be the smallest index with rank r i . Then r i = r i +1 = . . . = r i and we need to consider the following two cases.
(i) If i ≥ 2 then it cannot be in the top row, for otherwise r i −1 = r i contradicting our choice of i . Assume the index above i is p, and the index above i+1 is q. Then p < q < i < i + 1 by the Filling algorithm, and we have r i = r p + 1, r i+1 = r q + 1 by the Ranking algorithm. Thus r q ≤ r i by the induction hypothesis and we obtain r i+1 − r i ≤ r i+1 − r q = 1. On the other hand, r i+1 − r i = r q − r p , which is greater than or equal to 0 (again) by the induction hypothesis. (ii) If i = 1 then 0 = r 1 = r 2 = · · · = r i . It follows that indices 1, 2, . . . , i are all in row 1 and hence i + 1 is placed under 1, which implies 0 = r i < r i+1 = 1.
We will give two proofs of this lemma in the next section. The first one only considers the equal parameter case T ∈ T k n . One will see that the idea extends but the notation becomes awkward for T ∈ T k . The second one uses standard terminology from graph theory.
Proof of Theorem 1.12. By Lemma 2.4, we may write σ(D) = a 1 a 2 · · · a |k|+n . Assume the corresponding ranks are r 1 , r 2 , . . . , r |k|+n . Define D to be the SW-sequence obtained from σ(D) by replacing each top row index t i with an S k i and every other index by a W . We need to show that Φ(D) = D. This follows from the following two facts.
Fact 1: The rank sequence of D is exactly (r 1 , r 2 , . . . , r |k|+n ). This is consistent with the rule r j+1 = r j + k if a j is equal to t i and r j+1 = r j − 1 if a j is below row 1. Fact 2: The sweep order is from right to left when two ranks are equal. This corresponds to that for equal rank entries, their corresponding indices are increasing from right to left in σ(D).

Proof of Lemma 2.4
3.1. First proof. We only consider the equal parameter case T ∈ T k n . We need the following notation. One will see that the notation becomes awkward for T ∈ T k .
Let D be a Dyck path in D kn,n with index-rank tableau (T (D), R(D)). For any integer r, we denote by n(r) the number of r's appearing in R(D), so n(r) = 0 if r < 0. We also denote by n − (r) and n ∧ (r) the number of r's in the top row and the number of r's below the top row respectively. Similarly, we denote by n − (r) and n ∨ (r) the number of r's in the bottom row and the number of r's above the bottom row respectively. Then the following three equalities are clear. (1) The ranks of D have the common divisor n.
(2) For a word ω ∈ S n W m and 1 ≤ i ≤ m+n denote by a i (ω) and b i (ω), the numbers of "W " and "S" respectively that occur in the first i letters of ω. It is important to notice that we will have ω = SW(D) for some D ∈ D m,n if and only if (3) If a rank r appears in R(D), it will appear at most n times and n(r) = n − (r − k) + n ∧ (r + 1).

Proof.
(1) Because we start with assigning 0 to the south end of the first North step, this done we add an m = kn as we go North and subtract an n as we go East, all the ranks are divisible by n.
(3) Since every column of R(D) is strictly increasing, any rank r may appear at most n times. The equality n(r) = n − (r − k) + n ∧ (r + 1) follows from equation (3).
In the equal parameter case, Algorithm 1.11 terminates only after we mark the smallest rank 1 entry and write down its index.
Proof. Suppose the algorithm terminates after we mark a rank r entry and write down its index a.
If a is in row 1, then all rank r + k entries have been marked. But to mark a rank r + k entry, we can either go from a rank r whose index is in row 1, or go from a rank r + k + 1 entry whose index is not in row 1. Thus the number of marked rank r + k entry is at most n − (r) + n ∧ (r + k + 1) − 1, which is equal to n(r + k) − 1 by the equality in Lemma 3.1(3). This is a contradiction.
If a is not in row 1, then r ≥ 1 and there is no unmarked rank r − 1 for the walking algorithm to terminate. We have the following two cases.
(1) If r > 1, then we show the contradiction that there is at least one unmarked rank r − 1 entry so that the algorithm will not terminate. Or equivalently the number of marked r − 1 is at most n(r − 1) − 1. According to the walking algorithm, to mark a rank r − 1 entry, we can either go from a rank r − 1 − k whose index is in the top row, or go from a rank r entry whose index is not in the top row. Thus the number of marked rank r − 1 entry is at most n − (r − 1 − k) + n ∧ (r) − 1, which is equal to n(r − 1) − 1 by the equality in Lemma 3.1(3). (2) If r = 1 and we stopped at the non-smallest rank 1 entry, then we show the contradiction that there is at least one unmarked rank 0 entry so that the algorithm will not terminate. Or equivalently the number of marked rank 0 entries is at most n(0) − 1. The reason is similar. According to the walking algorithm, to mark a rank 0 entry, we can either mark the largest rank 0 entry at the first step, or go from a rank 1 entry whose index is not in the top row. Since we stopped at the non-smallest rank 1 entry, the number of marked rank 0 entry is at most 1 + n ∧ (1) − 2 = n ∧ (1) − 1, which is equal to n(0) − 1 by the equality in Lemma 3.1(3).
First Proof of Lemma 2.4. Now we are ready to show that Algorithm 1.11 terminates after we write down all of the m + n indices. Assume to the contrary that the algorithm terminates after we write down only p < m + n indices. Denote the resulting σ(D) by a i 1 , a i 2 , a i 3 , . . . , a ip , with corresponding ranks r i 1 , r i 2 , r i 3 , . . . , r ip . Then r i 1 = 0, r i 2 = k, and r ip = 1 is the smallest rank 1 by Lemma 3.2. Note that all rank 0 indices have been written. In particularly, index 1 is written. Moreover, for each j with 1 ≤ j < p either r i j + k = r i j+1 or r i j − 1 = r i j+1 .
Arrange the unwritten indices in increasing order as 1 < a i p+1 < a i p+2 < · · · < a i m+n , and denote their corresponding ranks by r i p+1 ≤ r i p+2 ≤ r i p+3 ≤ . . . ≤ r i m+n . By our choice a i p+1 − 1 is a written index, so assume a i j = a i p+1 − 1 for some j ≤ p. Now we have two cases, both leading to contradictions.
(1) If r i p+1 = r i j , then the walking algorithm would have prefered to writting index a i p+1 than a i j when visiting rank r i j . (2) If r i j < r i p+1 , then a i p+1 is not in row 1. By definition of a i p+1 and the increasing ranks of the indices in Lemma 2.3, all rank α = r i j entries have been marked. But to mark a rank α entry, we can either go from a rank α − k in top row, or from a rank α + 1 below top row (including the index a i p+1 with r i p+1 ). These implies that there are at most n(α − k) + n(α + 1) − 1 = n(α) − 1 (by 3.1(3)) rank α entries have been marked, a contradiction.
3.2. Second proof. Our second proof assumes basic knowledge of graph theory.
Firstly we construct a digraph G R from the rank tableau R = R(D) as follows. The vertices of G R are the ranks appearing in R. Each directed edge of G is associated to an index of T : i) if the index is t i and has rank a, then the directed edge is a → a + k i ; ii) if the box is not in row 1 and has rank b, then the directed edge is b → b − 1.
Each rank a of G R is associated with a set S(a) consisting of all indices with rank a. Denote by F (T ) = {t 1 , . . . , t n } the set of fist row indices of T arranged increasingly. Lemma 3.3. The digraph G R of a rank tableau R = R(D) is balanced. That is, each rank a of G has in-degree equal to out-degree, and equal to |S(a)|.
Proof. Let C i be the digraph obtained by restricting G to the i-th column of R. Then C i is clearly a directed cycle r → r + k i → · · · → r + 2 → r + 1 → r, where r is the rank in row 1. The in-degree and out-degree of a rank a are both 1 if a appears in C i and are 0 if otherwise. The lemma then follows since G is the union of C i for i = 1, 2, . . . , n.
The walking algorithm can be restated as a modified Eulerian tour as follows.
Algorithm 3.4 (Walking Algorithm G). Input: The digraph G R together with S(a) associated to every vertex a, and F (T ) as above.
Output: A permutation σ(D) through walking on G R .
(1) In G R , go to rank 0, mark the largest index in S(0) and write down it; (2) Repeat the following steps.
(a) Suppose we are at rank r and has just marked t i in F (t). If there is no unmarked index in S(r + k i ), then terminates. Otherwise, go to rank r + k i , mark the largest unmarked index in S(r + k i ) and write down it; (b) Suppose we are at rank r and has just marked an index not in F (t). If there is no unmarked index in S(r − 1), then terminates. Otherwise, go to rank r − 1, mark the largest unmarked index in S(r − 1) and write down it.
Second Proof of Lemma 2.4. Assume to the contrary that the algorithm terminates after we write down σ(D) = a 1 a 2 · · · a p for p < |k| + n. Then r(a 1 ) = 0.
Firstly we claim that r(a p ) = 1, and the algorithm terminates when we are trying to go to rank 0. This is simply due to the following observations: i) the in-degree and out-degree of rank r is |S(r)|; ii) every time when marking an index in S(r), we used one in-degree and one out-degree (including the attempt to go out); iii) the assumption that every index of S(r) has been marked implies that all the in-degree and out-degree has been used, and hence there is no more edges in G R directed to rank r. The only exceptional case is when r = 0, because we starting by marking the largest rank 0 index without using its in-degree. Now C = r(a 1 ) → r(a 2 ) → · · · r(a p ) → r(a 1 ) is a directed cycle contained in G R as a subgraph. Let b be the smallest unwritten index. Then b − 1 = a i ≥ 1 for some i ≤ p, since all rank 0 indices have been written. By Lemma 2.3 r(b) − r(a i ) is either 0 or 1. Both cases lead to contradictions. i) If r(b) = r(a i ), then the walking algorithm would have preferred to writing index b than a i when visiting rank r(b). ii) If r(b) = r(a i ) + 1, then b is not in row 1 by the ranking algorithm, and hence will be associated to a directed edge e = r(b) → r(b) − 1 in G R . Now observe that S(r(b) − 1) are all contained σ(D). This implies that the directed cycle C contains all directed edges into r(b) − 1, in particular the edge e. Then the walking algorithm must have written b already, which contradicts the choice of b.