Exact Sampling of Permutations with a Fixed Longest Increasing Subsequence

Peter Clifford
Department of Statistics
University of Oxford
United Kingdom

,

Raphaël Clifford
Department of Computer Science
University of Bristol
United Kingdom


Abstract

We study exact uniform sampling of permutations of length \(n\) whose longest increasing subsequence (LIS) has prescribed length \(k\). For \(k \in \Theta(n)\), we give a direct rejection sampler whose expected running time is \(O(n\log\log n)\) in the word-RAM model. The sampler uses an expanded proposal space consisting of permutations together with a specified increasing subsequence, and accepts exactly those proposals whose specified subsequence is the leftmost LIS. For arbitrary \(1\le k\le n\), we give an exact sampler based on the Robinson–Schensted correspondence. The algorithm samples the corresponding Plancherel-conditioned shape by computing exact completion counts via determinant identities, and then samples two uniform tableaux of that shape. The direct implementation runs in \(\tilde{O}(n^4k^5)\) expected time. We then show that the same sampler can be implemented in expected \(\tilde{O}(n^3k^4)\) time by evaluating a determinant oracle through Hankel moment matrices.

1 Introduction↩︎

The longest increasing subsequence problem has been a topic of great interest studied from several complementary viewpoints. On static inputs, the classical exact computation problem admits an \(O(n\log n)\) comparison-based algorithm [1]. For permutations of \([n]\), faster word-RAM algorithms are known. In particular, the standard predecessor-based implementation gives \(O(n\log\log n)\) time, and Crochemore and Porat give an \(O(n\log\log \ell)\) bound in terms of the LIS length \(\ell\) [2]. Later work developed streaming and sublinear-time approximation algorithms for \(\operatorname{LIS}\) and distance to monotonicity [3][5]. On dynamic inputs, variants of the problem have been studied in sliding-window and fully dynamic models [6][9]. On random permutations, the Robinson–Schensted correspondence connects \(\operatorname{LIS}\) to Plancherel-distributed Young diagrams. This viewpoint is rooted in the Ulam–Hammersley problem and Hammersley’s interacting particle process, and leads to the limit-shape results of Logan–Shepp and Vershik–Kerov and the fluctuation theorem of Baik–Deift–Johansson. Subsequent work connects these Plancherel asymptotics with random matrix theory and determinantal processes. See also the surveys of Aldous–Diaconis and Stanley [10][19]. For a comprehensive introduction to the mathematics of the longest increasing subsequence, see [20].

Despite this extensive literature, a basic algorithmic question has apparently gone unaddressed: how does one sample a permutation of length \(n\) uniformly at random, subject to the constraint that its \(\operatorname{LIS}\) has a prescribed length \(k\)? For a permutation \(\pi\in S_n\), let \(\operatorname{LIS}(\pi)\) denote the length of its longest increasing subsequence. Given input parameters \((n, k)\), we want to sample exactly from the uniform distribution on \[\Omega_{n,k}:=\{\pi\in S_n:\operatorname{LIS}(\pi)=k\}.\]

Rejection sampling from \(S_n\) does not give a polynomial-time algorithm as the probability that a uniform random permutation has \(\operatorname{LIS}\) equal to a specific \(k\) can be as small as \(1/n!\). One could in principle attempt to sample from \(\Omega_{n,k}\) via Markov chain Monte Carlo, but no Markov chain on \(\Omega_{n,k}\) with a provable polynomial mixing time is known, and our samplers are exact rather than approximate.

The closest works we are aware of concern exact sampling problems in the same Robinson–Schensted and Young-tableau setting, but not uniform sampling of permutations with a prescribed LIS. Thomas and Yong interpret Hecke insertion as an exact polynomial-time sampler for a Plancherel-type measure, and Betea, Boutillier, Bouttier, Chapuy, Corteel, and Vuletić give perfect sampling algorithms for Schur processes [21], [22]. To the best of our knowledge, the exact uniform sampling problem for \(\Omega_{n,k}\) has not been studied.

2 Our Results↩︎

We first give a fast direct sampler for the regime \(k\in\Theta(n)\). The sampler uses rejection sampling on an expanded proposal space of pairs \((\pi,I)\), where \(I\) is a distinguished \(k\)-term increasing subsequence of \(\pi\). A permutation with several LISs may have several representatives in this expanded space, so we use a canonical rule that accepts only the pair in which \(I\) is the leftmost LIS. Thus each permutation with \(\operatorname{LIS}=k\) contributes exactly one accepted proposal. We then prove that, when \(k\in\Theta(n)\), the acceptance probability is bounded below by a positive constant, giving the claimed expected running time.

Theorem 1 (Large-\(k\) direct sampler). Suppose \(k\in\Theta(n)\). There is an exact sampler for the uniform distribution on \(\Omega_{n,k}\) whose expected running time in the word-RAM model is \(O(n\log\log n)\), where the implicit constant may depend on the constants in \(k\in\Theta(n)\).

For general \(k\), the acceptance probability of the rejection sampler can be too small and so we must take an entirely different approach. The Robinson–Schensted correspondence gives a bijection between permutations of \([n]\) and pairs of Young tableaux, often written as a pair \((P, Q)\). It also identifies \(\operatorname{LIS}(\pi)\) with the first row length of the associated partition shape \(\lambda\). Figure 1 shows an example of the correspondence. The number of permutations of shape \(\lambda\) equals \((f^\lambda)^2\), where \(f^\lambda=|\operatorname{SYT}(\lambda)|\) is the number of standard Young tableaux of shape \(\lambda\) [23]. Thus uniform sampling from \(\Omega_{n,k}\) is equivalent to sampling a partition \(\lambda\vdash n\) from \[\mathbf{P}_{n,k}(\lambda)\propto (f^\lambda)^2\,\mathbf{1}_{\{\lambda_1=k\}},\] and then sampling a uniform pair of tableaux of shape \(\lambda\). Given a pair of tableaux, we can then recover the sampled permutation by the inverse Robinson–Schensted correspondence, implemented by reverse insertion. Unfortunately a naive dynamic program over Young diagrams may have superpolynomially many states, since there are \(\exp(\Theta(\sqrt n))\) partitions of \(n\). The Robinson–Schensted reduction and the step of randomly sampling tableaux of a fixed shape are standard, leaving open the question of how to sample the partition \(\lambda\) efficiently.

Figure 1: An example of the Robinson–Schensted correspondence. The permutation \pi=3152647 corresponds to a pair (P,Q) of standard Young tableaux of common shape. The first row length is 4, which equals \operatorname{LIS}(\pi).

Our main contribution is an exact sampler for the conditioned shape distribution. The sampler can be viewed as an exact dynamic program over shapes, but with the large completion sums compressed into determinant coefficients. First, we rewrite the shape problem as a weighted fixed-sum problem over strict partitions, that is partitions with distinct parts. Then we expose the sequence one coordinate at a time, choosing each candidate with probability proportional to the total remaining weight of all completions below that candidate. These completion weights are not computed by enumerating completions. Instead, the Cauchy–Binet formula turns each completion sum, which contains a squared Vandermonde factor, into a coefficient of the determinant of a matrix whose entries are polynomials in an auxiliary variable. This determinant representation is what makes the general sampler polynomial-time. The simplest implementation evaluates this determinant oracle separately for each candidate at a stage, which already gives a polynomial-time exact sampler. The direct implementation result is stated in Theorem 2 and proved in Section 5.

Theorem 2 (General exact sampler, direct implementation). For every \(1\le k\le n\), there is an exact sampler for the uniform distribution on \(\Omega_{n,k}\). In the word-RAM model, the direct implementation has expected running time \[\tilde{O}\!\bigl(n^4k^5\bigr).\]

The direct implementation above is self-contained apart from standard determinant computation and already gives a polynomial-time exact sampler for all \(1\le k\le n\). We also give a faster implementation of the same sequential sampler. This speedup does not change the distributional argument. It only changes how the completion scores at one stage are evaluated. The faster implementation uses a superfast Hankel determinant primitive as a structured-linear-algebra black box.

For the word-RAM analysis, the integer completion scores are computed modulo word-size primes and reconstructed by Chinese remaindering. This keeps all field operations at unit word cost, and the number of primes contributes the \(\tilde{O}(kn)\) overhead accounted for in the running-time bounds below. Theorem 3 gives the final result.

Theorem 3 (General exact sampler, fast implementation). For every \(1\le k\le n\), the same sampler can be implemented in \[\tilde{O}\!\bigl(n^3k^4\bigr)\] expected time, by representing the evaluated determinant matrices through their Hankel moment sequences and applying a superfast Hankel determinant algorithm over finite fields.

The key point is that the completion sums driving the sequential sampler, which can be exponentially large in \(n\), are never enumerated. Each is evaluated exactly as a single determinant coefficient via the Cauchy–Binet formula, and at each stage all candidate determinants are computed together by exploiting their shared Hankel structure.

3 A direct sampler when \(k \in \Theta(n)\)↩︎

Our direct sampler works directly with permutations and uses rejection sampling. The proposal distribution is supported on an expanded space of pairs \((\pi,I)\), where \(I\) is a \(k\)-term increasing subsequence of the permutation \(\pi\). The acceptance rule is designed so that, for each permutation with \(\operatorname{LIS}=k\), exactly one associated pair is accepted: the pair for which \(I\) is the leftmost LIS. The role of the leftmost LIS is simply as a canonical choice of LIS that can be computed rapidly.

Throughout this section let \(m:=n-k\). The construction and its exactness are valid for every \(1\le k\le n\). The constant acceptance-probability bound, and hence the final expected-time bound, will be proved only for sequences \(k=k(n)\) with \(k\in\Theta(n)\).

Define the expanded proposal space \[\mathcal{E}_{n,k}:= \{(\pi,I): \pi\in S_n,\; I=(i_1<\cdots<i_k),\; \pi(i_1)<\cdots<\pi(i_k)\}.\] Thus \(I\) is a list of positions whose entries form an increasing subsequence of \(\pi\) of length \(k\).

We sample a pair \((\pi,I)\in\mathcal{E}_{n,k}\) as follows.

  1. Choose a \(k\)-subset \(V\subseteq[n]\) uniformly.

  2. Choose a \(k\)-subset \(I\subseteq[n]\) uniformly.

  3. Place the values of \(V\) in increasing order into the positions \(I\).

  4. Fill the remaining \(m\) positions with the remaining \(m\) values in a uniformly random order.

We identify \(I\) with its increasing list of positions.

Proposition 4. The construction above is uniform on \(\mathcal{E}_{n,k}\). In particular, \[|\mathcal{E}_{n,k}|=\binom{n}{k}^{\!2}\!m! =\binom{n}{m}^{\!2}\!m!.\]

Proof. The choices made by the proposal are exactly a \(k\)-set of values \(V\), a \(k\)-set of positions \(I\), and an ordering of the remaining \(m=n-k\) values. Given these data, the entries on \(I\) are forced to be the elements of \(V\) in increasing order, and the remaining entries are filled according to the chosen ordering.

Conversely, given \((\pi,I)\in\mathcal{E}_{n,k}\), the set \(V\) is uniquely the set of values \(\{\pi(i):i\in I\}\), and the ordering of the remaining values is read off from \(\pi\) outside \(I\). Thus the proposal data are in bijection with \(\mathcal{E}_{n,k}\). Since the proposal data are chosen uniformly, the induced law on \(\mathcal{E}_{n,k}\) is uniform. The cardinality formula follows from the same bijection and the fact that \(\binom{n}{k} = \binom{n}{n-k}\). ◻

For a permutation \(\pi\) with \(\operatorname{LIS}(\pi)=k\), let \(L^\star(\pi)\) denote the leftmost LIS of \(\pi\): among all increasing subsequences of length \(k\), choose the one whose list of positions is lexicographically smallest.

Figure 2: Direct rejection sampler

Proposition 5. Conditioned on acceptance in one iteration of Algorithm 2, the output permutation is uniform on \(\Omega_{n,k}\).

Proof. The accepted proposals are precisely the pairs \[\mathcal{A}_{n,k}:= \{(\pi,I)\in\mathcal{E}_{n,k}:\operatorname{LIS}(\pi)=k \text{ and } I=L^\star(\pi)\}.\] The projection \((\pi,I)\mapsto\pi\) is a bijection from \(\mathcal{A}_{n,k}\) to \(\Omega_{n,k}\): for each \(\pi\in\Omega_{n,k}\) there is exactly one accepted pair, namely \((\pi,L^\star(\pi))\).

By Proposition 4, the proposal distribution is uniform on \(\mathcal{E}_{n,k}\). Therefore all accepted pairs have equal probability. Since accepted pairs are in bijection with \(\Omega_{n,k}\), the output permutation is uniform on \(\Omega_{n,k}\). ◻

3.1 Testing one proposal in \(O(n\log \log n)\) time↩︎

We first show that an individual proposal can be accepted or rejected in \(O(n\log \log n)\) time. For a permutation \(\pi\in S_n\) and an index \(i\in[n]\), let \(r_i\) be the length of the longest increasing subsequence of \(\pi\) that starts at position \(i\).

Fact 6. Let \(a\in S_n\). In the word-RAM model, one can compute, for every \(j\in[n]\), the length \(d_j\) of the longest increasing subsequence of \(a\) ending at position \(j\) in \(O(n\log\log n)\) time.

This is the standard patience-sorting dynamic program with the ordered set of current tail values implemented by an integer predecessor structure, such as a van Emde Boas structure. See, e.g., Crochemore and Porat [2].

Lemma 1. The values \(r_1,\dots,r_n\) can be computed in \(O(n\log \log n)\) time in the word-RAM.

Proof. Let \(b_j=n+1-\pi_{n+1-j}\) be the reversed-complement permutation. An increasing subsequence of \(\pi\) starting at position \(i\) corresponds bijectively to an increasing subsequence of \(b\) ending at position \(n+1-i\). Hence \(r_i=d_{n+1-i}\), where \(d_j\) is the length of the longest increasing subsequence of \(b\) ending at \(j\). By Fact 6, all \(d_j\) are computed in \(O(n\log\log n)\) time, and reading them in reverse gives all \(r_i\) in the same time. ◻

Assume now that \(\operatorname{LIS}(\pi)=k\). We construct the leftmost LIS greedily. Starting with the dummy values \(i_0:=0\) and \(v_0:=0\), suppose that \(i_1,\dots,i_{t-1}\) have already been chosen and write \(v_{t-1}:=\pi(i_{t-1})\). We choose \(i_t\) to be the smallest index \(i>i_{t-1}\) such that \(\pi(i)>v_{t-1}\) and such that an increasing subsequence of length \(k-t+1\) can still be completed starting from \(i\), that is, \[r_i\ge k-t+1.\] We then set \(v_t:=\pi(i_t)\).

Lemma 2. If \(\operatorname{LIS}(\pi)=k\), the greedy reconstruction above returns \(L^\star(\pi)\).

Proof. We argue by induction on \(t\). Suppose \(i_1,\dots,i_{t-1}\) have already been chosen and coincide with the first \(t-1\) positions of the leftmost LIS. Let \[F_t:=\{i>i_{t-1}:\pi(i)>v_{t-1},\;r_i\ge k-t+1\}.\] Every index in \(F_t\) can be used as the next position of an increasing subsequence of total length \(k\). The already chosen prefix has length \(t-1\), and since \(i>i_{t-1}\), \(\pi(i)>v_{t-1}\), and \(r_i\ge k-t+1\), it can be followed by an increasing subsequence of length \(k-t+1\) starting at \(i\). Conversely, the \(t\)th position of any LIS extending \(i_1,\dots,i_{t-1}\) must lie in \(F_t\). The greedy rule picks the smallest index in \(F_t\), so no lexicographically smaller LIS can differ for the first time at position \(t\). Thus the chosen \(i_t\) is exactly the \(t\)th position of \(L^\star(\pi)\). ◻

Corollary 1. Given a proposal \((\pi,I)\), one can decide whether it is accepted by one iteration of Algorithm 2 in \(O(n\log\log n)\) time on the word-RAM.

Proof. Compute the values \(r_i\) using Lemma 1, in \(O(n\log\log n)\) time. Their maximum is \(\operatorname{LIS}(\pi)\). If this maximum is not \(k\), reject immediately. Otherwise reconstruct \(L^\star(\pi)\) using Lemma 2. The reconstruction is a single left-to-right scan through the permutation and therefore costs \(O(n)\) time. Finally compare the reconstructed list of positions with \(I\), again in \(O(n)\) time. The total time is \(O(n\log\log n)\). ◻

3.2 Acceptance probability↩︎

For a partition \(\nu\) and a box \(u=(i,j)\) in its Young diagram, let \(h_\nu(u)\) denote the hook length of \(u\), namely the number of boxes consisting of \(u\) itself, the boxes to the right of \(u\) in the same row, and the boxes below \(u\) in the same column. Equivalently, \[h_\nu(i,j)=\nu_i-j+\nu'_j-i+1.\] Write \(H_\nu:=\prod_{u\in\nu}h_\nu(u)\). We use the hook-length formula of Frame–Robinson–Thrall, \[f^\nu=\frac{|\nu|!}{H_\nu},\] where \(f^\nu=|\operatorname{SYT}(\nu)|\) is the number of standard Young tableaux of shape \(\nu\) [24].

For a partition \(\lambda=(\lambda_1,\lambda_2,\dots)\), let \(\lambda'\) denote the conjugate partition, whose parts are the column lengths of the Young diagram of \(\lambda\). For the empty partition we use the convention \(\mu_1=0\) and interpret empty products as \(1\).

Any shape with first row of length \(k\) can be written as \(\lambda=(k,\mu)\), where \(\mu\vdash m\) is the sub-diagram below the first row. The factor \(a_k(\mu)\) measures the multiplicative loss in \(f^{(k, \mu)}\) caused by the elongation of the first-row hooks relative to a bare row of length \(k\). In column \(j\), the hook length in an isolated row would be \(k-j+1\). Placing \(\mu\) underneath elongates it by the column height \(\mu'_j\) to \(k-j+1+\mu'_j\). Columns \(j>\mu_1\) are unaffected. For \(\mu\vdash m\), define \[a_k(\mu):= \begin{cases} \displaystyle \prod_{j=1}^{\mu_1}\frac{k-j+1}{k-j+1+\mu'_j}, & \mu_1\le k,\\[1.2em] 0,& \mu_1>k. \end{cases}\] The hook-length formula then yields \(f^{(k,\mu)}=\binom{n}{m}f^\mu\,a_k(\mu)\), where the binomial coefficient accounts for the choice of which \(m\) labels descend below the first row. Squaring and summing over \(\mu\) will express \(|\Omega_{n,k}|\) as a Plancherel expectation, from which the acceptance probability of the rejection sampler follows directly. To that end, define \[A_{n,k}:=\mathbf{E}_{\operatorname{Pl}_m}[a_k(\mu)^2], \qquad \operatorname{Pl}_m(\mu)=\frac{(f^\mu)^2}{m!}.\]

Lemma 3. For \(\lambda=(k,\mu)\) with \(\mu\vdash m\) and \(\mu_1\le k\), \[f^\lambda=\binom{n}{m}f^\mu a_k(\mu).\] Consequently, \(|\Omega_{n,k}|=\binom{n}{m}^2m!\,A_{n,k}\).

Proof. For \(\lambda=(k,\mu)\), the hooks below the first row are those of \(\mu\), contributing \(H_\mu\). The first-row hooks are \(k-j+1+\mu'_j\) for \(1\le j\le\mu_1\) and \(k-j+1\) for \(\mu_1<j\le k\), so \[H_\lambda = H_\mu\,\frac{\prod_{j=1}^{\mu_1}(k-j+1+\mu'_j)}{\prod_{j=1}^{\mu_1}(k-j+1)}\cdot k! = H_\mu\,\frac{k!}{a_k(\mu)}.\] The hook-length formula then gives \[f^\lambda = \frac{n!}{H_\lambda} = \frac{n!}{m!\,k!}\cdot\frac{m!}{H_\mu}\cdot a_k(\mu) = \binom{n}{m}f^\mu a_k(\mu).\] For the second claim, Robinson–Schensted identifies \(\Omega_{n,k}\) with pairs of tableaux of shapes \((k,\mu)\), \(\mu\vdash m\), \(\mu_1\le k\) [23], so \[|\Omega_{n,k}| = \sum_{\substack{\mu\vdash m\\\mu_1\le k}}(f^{(k,\mu)})^2 = \binom{n}{m}^{\!2}\sum_{\mu\vdash m}(f^\mu)^2 a_k(\mu)^2 = \binom{n}{m}^{\!2}m!\,A_{n,k}.\qedhere\] ◻

Corollary 2. The acceptance probability of one iteration of Algorithm 2 is \(|\Omega_{n,k}|/|\mathcal{E}_{n,k}|=A_{n,k}\).

Proof. By Proposition 5, every permutation in \(\Omega_{n,k}\) contributes exactly one accepted pair \((\pi,I)\), so the acceptance probability equals \(|\Omega_{n,k}|/|\mathcal{E}_{n,k}|\). The result now follows from Proposition 4 and Lemma 3. ◻

To bound \(A_{n,k}\) below by a positive constant, we need that \(\mu_1\) is not too large under Plancherel measure.

Lemma 4. For every \(m\ge 1\), if \(\mu\) is drawn from Plancherel measure on partitions of \(m\), then \(\mathbf{P}_{\operatorname{Pl}_m}(\mu_1\le 4\sqrt{m})\ge\tfrac{1}{2}\).

Proof. By the Robinson–Schensted correspondence, \(\mu_1\) under Plancherel measure has the same distribution as \(\operatorname{LIS}(\sigma)\) for a uniform random permutation \(\sigma\) of \([m]\). Fix \(r\ge 1\) and let \(X_r\) count the increasing subsequences of length \(r\) in \(\sigma\). Each \(r\)-subset of positions contributes with probability \(1/r!\), so \(\mathbf{E}X_r=\binom{m}{r}/r!\). Since \(\operatorname{LIS}(\sigma)\ge r\) implies \(X_r\ge 1\), Markov’s inequality gives \[\mathbf{P}_{\operatorname{Pl}_m}(\mu_1\ge r)=\mathbf{P}(\operatorname{LIS}(\sigma)\ge r)\le\mathbf{E}X_r=\frac{\binom{m}{r}}{r!}.\] Using \(\binom{m}{r}\le(em/r)^r\) and \(r!\ge(r/e)^r\) yields \(\mathbf{P}_{\operatorname{Pl}_m}(\mu_1\ge r)\le(e^2m/r^2)^r\). Taking \(r=\lfloor 4\sqrt{m}\rfloor+1>4\sqrt{m}\), \[\mathbf{P}_{\operatorname{Pl}_m}(\mu_1>4\sqrt{m}) \le\mathbf{P}_{\operatorname{Pl}_m}(\mu_1\ge r) \le\left(\frac{e^2}{16}\right)^r \le\frac{1}{2},\] which proves the claim. ◻

Lemma 4 gives the tail bound on \(\mu_1\) needed to control \(a_k(\mu)\) on a set of positive Plancherel probability, from which the constant lower bound follows.

Lemma 5. Fix \(\eta\in(0,1]\). If \(k\ge \eta n\), then for all sufficiently large \(n\), \[A_{n,k}\ge \frac{1}{2}\exp\!\left(-\frac{4(1-\eta)}{\eta}\right).\] In particular, if \(k\in\Theta(n)\), then there are constants \(c>0\) and \(n_0\) such that \(A_{n,k}\ge c\) for all \(n\ge n_0\).

Proof. If \(m=0\), then \(k=n\) and \(A_{n,n}=1\), which is larger than the displayed lower bound. Hence assume \(m=n-k\ge 1\). Since \(k\ge\eta n\), we have \[\frac{m}{k}=\frac{n-k}{k}\le\frac{1-\eta}{\eta}.\]

Using \(\log(1+x)\le x\), whenever \(\mu_1\le k\) we have \[-\log a_k(\mu) =\sum_{j=1}^{\mu_1}\log\!\left(1+\frac{\mu'_j}{k-j+1}\right) \le\sum_{j=1}^{\mu_1}\frac{\mu'_j}{k-j+1} \le\frac{m}{k-\mu_1+1},\] where the last step uses \(\sum_{j=1}^{\mu_1}\mu'_j=m\).

By Lemma 4, the event \(\{\mu_1\le 4\sqrt{m}\}\) has probability at least \(1/2\). Since \(m\le ((1-\eta)/\eta)k\), for all sufficiently large \(n\) this event implies \(\mu_1\le k/2\), and in particular \(\mu_1\le k\). Hence \(k-\mu_1+1\ge k/2\). On this event, \[-\log a_k(\mu)\le\frac{2m}{k} \le\frac{2(1-\eta)}{\eta},\] and therefore \[a_k(\mu)^2\ge \exp\!\left(-\frac{4(1-\eta)}{\eta}\right).\] It follows that \[A_{n,k}=\mathbf{E}_{\operatorname{Pl}_m}[a_k(\mu)^2] \ge \frac{1}{2}\exp\!\left(-\frac{4(1-\eta)}{\eta}\right)\] for all sufficiently large \(n\).

The final assertion follows by choosing any \(\eta>0\) such that \(k\ge\eta n\) for all sufficiently large \(n\). ◻

Proof of Theorem 1. Exactness is established by Proposition 5. By Corollary 1, each proposal is tested in \(O(n\log\log n)\) time, and generating it takes \(O(n)\) time. By Corollary 2 and Lemma 5, the acceptance probability is bounded below by a positive constant for all sufficiently large \(n\), so the expected number of trials is \(O(1)\). The expected total running time is therefore \(O(n\log\log n)\). ◻

4 A polynomial-time algorithm for general \(k\)↩︎

We now turn to the general sampler. By the Robinson–Schensted correspondence, sampling a uniform permutation from \(\Omega_{n,k}\) reduces to two steps. First, sample a partition \(\lambda\vdash n\) from \[\mathbf{P}_{n,k}(\lambda)\propto (f^\lambda)^2\,\mathbf{1}_{\{\lambda_1=k\}},\] and second, sample two independent uniform tableaux of shape \(\lambda\) and apply the inverse correspondence. The second step is standard and is deferred to Section 4.4. The first step is the main algorithmic challenge.

4.0.0.1 Overview of the shape sampler.

The central challenge is to sample the Robinson–Schensted shape conditioned on first row length \(k\), where the target weight \((f^\lambda)^2\) is given by the hook-length formula. Direct enumeration over the up to \(\binom{n}{k}\) feasible shapes is not polynomial. Our algorithm overcomes this through three steps, each removing a distinct obstacle.

Step 1: Reparameterisation separates the factorial weights. We conjugate the partition and apply the shift \(x_i:=\rho_i+k-i\), rewriting the hook-length formula as \[(f^\lambda)^2\propto \Delta(x)^2\prod_{i=1}^k x_i!^{-2}.\] Thus the factorial part becomes a product of per-coordinate weights, while the remaining coordinate coupling is isolated in the squared Vandermonde factor \(\Delta(x)^2\). This separation is what makes the later Cauchy–Binet determinant oracle applicable.

Step 2: Sequential sampling reduces the problem to completion scores. The separated weight admits a one-coordinate-at-a-time sampler. Given a prefix \(p=(p_1,\dots,p_r)\), sample the next coordinate \(t\) with probability proportional to the total weight of all completions of \((p_1,\dots,p_r,t)\). These completion scores give the exact conditional distribution by construction. The obstacle is computing them. Each score sums over all valid suffixes, and the number of possible suffixes can be exponential in \(n\).

Step 3: Cauchy–Binet collapses the suffix sum. Hankel structure makes the oracle fast. Every suffix contribution contains \(\Delta(A)^2\), the squared Vandermonde product over the suffix elements. By the Cauchy–Binet formula this entire sum equals a single coefficient of the determinant of a polynomial matrix, replacing an exponential enumeration by a polynomial-time determinant. A further observation drives the faster implementation. When that matrix is evaluated at a fixed scalar \(\xi\), its \((i,j)\) entry depends only on \(i+j\), making it Hankel. A Hankel determinant of size \(L\) can be computed in \(\tilde{O}(L)\) arithmetic operations rather than \(O(L^3)\). Combined with an incremental sweep over candidates \(t\), this reduces the per-stage cost from \(\tilde{O}(n^4 k L^3)\) to \(\tilde{O}(n^3 k L^2)\) word operations, and the total sampling cost from \(\tilde{O}(n^4 k^5)\) to \(\tilde{O}(n^3 k^4)\).

Algorithm 3 gives the overall structure. The rest of this section formalises the weight formula, defines the completion scores, gives the determinant oracle, and proves correctness of the sequential shape sampler. Subsection 4.4 completes the reduction to permutations. Sections 5 and 6 analyse the direct and fast implementations respectively.

4.1 Reparameterisation↩︎

We work with the conjugate partition \(\rho=\lambda'\) rather than \(\lambda\) directly, its parts \(\rho_i\) are the column heights of \(\lambda\), and it is these that appear naturally in the hook-length formula. Since \(\lambda_1=k\), the partition \(\rho\) has exactly \(k\) positive parts, where \(\rho_i\) counts the rows of \(\lambda\) of length at least \(i\), satisfying \[\rho_1\ge\rho_2\ge\cdots\ge\rho_k\ge 1,\qquad \rho_1+\cdots+\rho_k=n.\] Set \(x_i:=\rho_i+k-i\) and \(N:=n+\binom{k}{2}\). The shift turns the weakly decreasing sequence \(\rho\) into the strictly decreasing sequence \[n\ge x_1>x_2>\cdots>x_k\ge 1,\qquad x_1+\cdots+x_k=N,\] and the map \(x\mapsto\rho\) given by \(\rho_i=x_i-k+i\) is its inverse. Thus the shapes \(\lambda\vdash n\) with \(\lambda_1=k\) are in bijection with the strict partitions \(x\) of \(N\) into exactly \(k\) parts, each at most \(n\). This is the same shift Johansson used to express Plancherel measure as a squared Vandermonde factor times independent weights [25]. Here we repurpose it for purely algorithmic purposes and apply it to the conjugate partition.

For a strict partition \(x=(x_1,\dots,x_k)\), write \(\Delta(x):=\prod_{1\le i<j\le k}(x_i-x_j)\).

The following lemma makes the factored form of the target weight explicit. It is the reason the \(x\) coordinates are useful. The hook-length formula, when rewritten in terms of \(x\), separates into a Vandermonde factor and independent factorial weights, yielding a target distribution that admits an efficient sequential sampler.

Lemma 6. Under the bijection above, \[f^\rho=n!\,\frac{\Delta(x)}{\prod_{i=1}^k x_i!}.\] Consequently the target distribution on strict partitions \(x\) is proportional to \[\operatorname{wt}(x):=\Delta(x)^2\prod_{i=1}^k x_i!^{-2}.\]

Proof. By the hook-length formula \(f^\rho=n!/H_\rho\). For row \(i\) of \(\rho\), the hook lengths \(h(i,c)=\rho_i-c+\rho'_c-i+1\) as \(c\) ranges from \(1\) to \(\rho_i\) give the integers \(1,\dots,\rho_i+k-i\) with the values \(\rho_i-\rho_j+j-i\) for \(j>i\) omitted. Hence \[\prod_{c=1}^{\rho_i}h(i,c) =\frac{(\rho_i+k-i)!}{\prod_{j>i}(\rho_i-\rho_j+j-i)}.\] Multiplying over \(i=1,\dots,k\) gives \[H_\rho =\frac{\prod_{i=1}^k(\rho_i+k-i)!}{\prod_{1\le i<j\le k}(\rho_i-\rho_j+j-i)}.\] Substituting \(x_i=\rho_i+k-i\) yields \((\rho_i+k-i)!=x_i!\) and \(\rho_i-\rho_j+j-i=x_i-x_j\), so \(H_\rho=\prod_i x_i!/\Delta(x)\) and \(f^\rho=n!\,\Delta(x)/\prod_i x_i!\).

Since transposition preserves the number of standard Young tableaux, \(f^\lambda=f^\rho\). Therefore \[(f^\lambda)^2=(f^\rho)^2=(n!)^2\Delta(x)^2\prod_i x_i!^{-2}.\] As \((n!)^2\) is independent of \(x\), the induced distribution on \(x\) is proportional to \(\operatorname{wt}(x)\). ◻

Figure 3: General exact sampler

We sample the strict sequence \(x_1>\cdots>x_k\) one coordinate at a time. At each step, having fixed a prefix \(p=(p_1,\dots,p_r)\) with \(p_1>\cdots>p_r\ge 1\), we choose the next coordinate \(t\) with probability proportional to the total \(\operatorname{wt}\)-mass of all valid extensions of \((p_1,\dots,p_r,t)\) to a full strict sequence. These masses are the completion scores \(S_p(t)\), which we define and compute below.

At a prefix \(p=(p_1,\ldots,p_r)\) of length \(r<k\), define the upper bound \[B(p):= \begin{cases} n, & r=0,\\ p_r-1, & r>0. \end{cases}\] The admissible candidates for the next coordinate are then \[t\in\{1,\ldots,B(p)\}.\]

For such an admissible \(t\), write \[L:=k-r-1,\quad s:=N-\textstyle\sum_{i=1}^r p_i-t,\quad E_t:=\{1,\dots,t-1\}.\] A valid suffix is an \(L\)-element subset \(A\subseteq E_t\) with \(\sum A=s\). For a finite set \(A\), write \[\Delta(A):=\prod_{\substack{a,b\in A\\a<b}}(b-a),\] with the convention \(\Delta(\varnothing)=1\). For a weight function \(\psi\) on \(E\), the completion counter is \[Z_{L,s}(E,\psi) :=\sum_{\substack{A\subseteq E\\|A|=L,\;\sum A=s}} \Delta(A)^2\prod_{a\in A}\psi(a),\] with \(Z_{0,s}(E,\psi)=\mathbf{1}_{s=0}\) since the only suffix of length zero is \(A=\varnothing\).

Since the sampler uses only relative probabilities at a fixed prefix, we may scale all completion masses by any common positive factor. We clear the factorial denominators of the unrevealed coordinates by multiplying through by \((n!)^{2(L+1)}\). For a possible later value \(a\), define \[G_p(a):=\Bigl(\frac{n!}{a!}\Bigr)^2\prod_{i=1}^r(p_i-a)^2,\] recording the scaled contribution of \(a\) and its pairwise interactions with the prefix. Fixing the next coordinate to \(t\) introduces a further pairwise factor \((t-a)^2\) for each suffix element \(a\), giving \[\psi_{p,t}(a):=(t-a)^2\,G_p(a).\] The completion score is then \[S_p(t):=G_p(t)\,Z_{L,s}(E_t,\psi_{p,t}), \qquad 1\le t\le B(p).\]

Figure 4: Sequential shape sampler

Remark 7. The completion scores \(S_p(t)\) are nonnegative integers, since \(G_p(a)\) is a perfect square of an integer and \(Z_{L,s}(E_t,\psi_{p,t})\) is a sum of products of such integers. Hence the weighted choice in Algorithm 4 can be implemented exactly using these integer weights. No rational probabilities need be formed.

Lemma 7. For a fixed prefix \(p\), the completion score \(S_p(t)\) is proportional to the total \(\operatorname{wt}\)-mass of all valid extensions of \(p\) with next coordinate \(t\), with a proportionality constant independent of \(t\).

Proof. Fix an admissible candidate \(t\in\{1,\ldots,B(p)\}\). Let \(U:=(p_1,\dots,p_r,t)\). For any valid suffix \(A\subseteq E_t\), the full extension is \((p_1,\dots,p_r,t,a_1,\dots,a_L)\), where \(a_1>\cdots>a_L\) are the elements of \(A\). Its Vandermonde factor separates as \[\Delta(U,A)^2 =\Delta(p)^2\prod_{i=1}^r(p_i-t)^2\, \Delta(A)^2\prod_{a\in A}(t-a)^2 \prod_{i=1}^r\prod_{a\in A}(p_i-a)^2 .\] Thus the full weight of this extension is \[C_p\, \frac{\prod_{i=1}^r(p_i-t)^2}{t!^2}\, \Delta(A)^2 \prod_{a\in A} \frac{(t-a)^2\prod_{i=1}^r(p_i-a)^2}{a!^2},\] where \(C_p:=\Delta(p)^2\prod_{i=1}^r p_i!^{-2}\) depends only on \(p\). Multiplying the non-prefix part by \((n!)^{2(L+1)}\) gives \[G_p(t)\,\Delta(A)^2\prod_{a\in A}\psi_{p,t}(a).\] Hence the total \(\operatorname{wt}\)-mass of all valid extensions with next coordinate \(t\) is \[C_p(n!)^{-2(L+1)}G_p(t)Z_{L,s}(E_t,\psi_{p,t}) =C_p(n!)^{-2(L+1)}S_p(t).\] The proportionality constant is independent of \(t\), so \(S_p(t)\) is proportional to the required total mass. ◻

4.2 A determinant oracle for completion counts↩︎

Recall that the completion score \(S_p(t)\) involves the counter \(Z_{L,s}(E_t,\psi_{p,t})\), a sum of \(\Delta(A)^2\)-weighted terms over all \(L\)-element subsets \(A\subseteq E_t\) with \(\sum A=s\). Enumerating these subsets directly is infeasible as there are \(\binom{t-1}{L}\) such subsets, which can be exponential in \(n\).The following lemma shows that \(Z_{L,s}(E,\psi)\) is instead recoverable as a single coefficient of the determinant of an \(L\times L\) polynomial matrix, and a determinant can be computed in polynomial-time.

The key mechanism is the factorisation \(M_{L,E,\psi}(q)=VD(q)V^\top\), where \(V\) is a Vandermonde matrix and \(D(q)\) is diagonal. The Cauchy–Binet formula expands the determinant as a sum over \(L\)-element index sets \(J\), each contributing \(\det(V_J)^2=\Delta(A)^2\) and a monomial \(q^{\sum A}\). The coefficient of \(q^s\) then collects exactly the terms in \(Z_{L,s}(E,\psi)\).

Let \(E=\{e_1<\cdots<e_m\}\) be a finite set of positive integers, \(R\) a commutative ring, and \(\psi:E\to R\) a weight function. For \(L\ge 0\), define the following \(L\times L\) matrix over \(R[q]\): \[M_{L,E,\psi}(q):=\sum_{y\in E}\psi(y)q^y\,v(y)v(y)^\top, \quad v(y):=(1,y,\dots,y^{L-1})^\top\in R^L.\]

Lemma 8 (Determinant oracle). For every \(L\ge 0\) and integer \(s\ge 0\), \[[q^s]\det M_{L,E,\psi}(q)=Z_{L,s}(E,\psi).\]

Proof. The case \(L=0\) is immediate. For \(L\ge 1\), write \(M_{L,E,\psi}(q)=VD(q)V^\top\) where \(V\) is the \(L\times m\) Vandermonde matrix with columns \(v(e_j)\) and \(D(q)=\operatorname{diag}(\psi(e_1)q^{e_1},\dots,\psi(e_m)q^{e_m})\). By the Cauchy–Binet formula [26], \[\det\bigl(VD(q)V^\top\bigr) =\sum_{\substack{J\subseteq[m]\\|J|=L}} \det(V_J)\det(D_J(q))\det(V_J^\top),\] where \(V_J\) and \(D_J(q)\) are the submatrices indexed by \(J\). Setting \(A=\{e_j:j\in J\}\), we have \(\det(V_J)=\Delta(A)\) and \(\det(D_J(q))=\prod_{a\in A}\psi(a)q^a\), so \[\det M_{L,E,\psi}(q) =\sum_{\substack{A\subseteq E\\|A|=L}} \Delta(A)^2\prod_{a\in A}\psi(a)\,q^{\sum A}.\] Extracting the coefficient of \(q^s\) gives \(Z_{L,s}(E,\psi)\). ◻

By Lemma 8, computing \(Z_{L,s}(E_t,\psi_{p,t})\) requires only extracting the coefficient \[[q^s]\det M_{L,E_t,\psi_{p,t}}(q),\] and the completion score is then \[S_p(t)=G_p(t)\,[q^s]\det M_{L,E_t,\psi_{p,t}}(q).\] Thus, for every prefix \(p\) and every candidate next coordinate \(t\), the total weight of all completions below \(t\) can be computed exactly by a determinant coefficient. We now use these scores to assemble the one-coordinate-at-a-time shape sampler and prove that its output has the required distribution. The running-time analysis of the direct and faster implementations is deferred to Sections 5 and 6.

4.3 The sequential shape sampler↩︎

We now assemble the one-coordinate-at-a-time sampler. Start with the empty prefix \(p=\varnothing\). At each stage, compute the completion scores \(S_p(t)\) for all admissible \(t\), then draw the next coordinate with probability \[\mathbf{P}(x_{r+1}=t\mid p) = \frac{S_p(t)}{\sum_{u=1}^{B(p)}S_p(u)}.\] For an admissible candidate \(t\), write \[s(t):=N-\sum_{i=1}^r p_i-t.\] A suffix of length \(L\) chosen from \(E_t=\{1,\ldots,t-1\}\) can have total sum only between the sum of the \(L\) smallest positive integers and the sum of the \(L\) largest elements below \(t\). Hence \(S_p(t)=0\) unless \[\binom{L+1}{2}\le s(t)\le Lt-\binom{L+1}{2}.\] Candidates failing this test may therefore be skipped before invoking the determinant oracle. After \(k\) coordinates have been chosen, recover \(\rho_i=x_i-k+i\) and set \(\lambda=\rho'\).

For a prefix \(p\), let \(W(p)\) denote the total \(\operatorname{wt}\)-mass of all valid full strict sequences extending \(p\).

Theorem 8. The sequential sampler outputs a strict partition \(x\) of \(N\) with \(k\) parts with probability proportional to \(\operatorname{wt}(x)\). Equivalently, it samples \(\lambda\vdash n\) with \(\lambda_1=k\) from the exact law \(\mathbf{P}_{n,k}(\lambda)\propto(f^\lambda)^2\,\mathbf{1}_{\{\lambda_1=k\}}\).

Proof. By Lemma 7, at every prefix \(p\) the drawn coordinate distribution is exactly proportional to the remaining target mass below each candidate. Telescoping, the probability of generating a complete partition \(x\) is \[\prod_{r=0}^{k-1}\frac{W(x_1,\dots,x_{r+1})}{W(x_1,\dots,x_r)} =\frac{\operatorname{wt}(x)}{W(\varnothing)},\] where \(W(x)=\operatorname{wt}(x)\) since a complete sequence has no further suffix. Hence the output law is proportional to \(\operatorname{wt}(x)\), and Lemma 6 identifies this with the target shape distribution. ◻

4.4 From sampled shapes to sampled permutations↩︎

The remaining steps are standard. We use the Robinson–Schensted bijection between permutations of \([n]\) and pairs \((P,Q)\) of standard Young tableaux of the same shape, together with its inverse reverse-insertion algorithm [27]. We also use the Greene–Nijenhuis–Wilf hook walk, which samples a uniform standard Young tableau of any fixed shape [28].

Lemma 9. Suppose that \(\lambda\vdash n\) is sampled from \[\mathbf{P}_{n,k}(\lambda)\propto (f^\lambda)^2\,\mathbf{1}_{\{\lambda_1=k\}}.\] Conditional on \(\lambda\), sample \(P\) and \(Q\) independently and uniformly from \(\operatorname{SYT}(\lambda)\), and output the inverse Robinson–Schensted image of \((P,Q)\). Then the output is a uniformly random permutation in \(\Omega_{n,k}\).

Proof. For fixed \(\lambda\), Robinson–Schensted identifies the permutations of shape \(\lambda\) with \(\operatorname{SYT}(\lambda)\times\operatorname{SYT}(\lambda)\). Hence the procedure gives each permutation of shape \(\lambda\) probability \[\mathbf{P}_{n,k}(\lambda)\cdot (f^\lambda)^{-2},\] which is independent of \(\lambda\) on the support \(\{\lambda\vdash n:\lambda_1=k\}\). Since Robinson–Schensted sends the LIS length to the first row length [23], this support is exactly \(\Omega_{n,k}\). ◻

5 The running time of a direct implementation of the general sampler↩︎

We now derive the running time of a direct implementation of the general sampler. We assume the word-RAM model with word size \(\Theta(\log n)\). All exact random choices are made from unbiased random bits1.

Fix an already sampled prefix \(p=(p_1,\dots,p_r)\) of \(x\), and write \[L:=k-r-1.\] Recall the reusable stage weights \[G_p(a)=\Bigl(\frac{n!}{a!}\Bigr)^2\prod_{i=1}^r(p_i-a)^2, \qquad a=1,\dots,n,\] and \[\psi_{p,t}(a)=(t-a)^2G_p(a).\] If the next chosen coordinate is \(u\), then \[G_{(p,u)}(a)=G_p(a)(u-a)^2.\] Thus the array \(\{G_p(a):1\le a\le n\}\) may be updated from one stage to the next by a single pass over \(a=1,\dots,n\). This update cost is lower order in the bounds below.

Lemma 10. For every prefix \(p\) with suffix length \(L\) and every feasible candidate \(t\), the integer completion score \(S_p(t)\) has \(O((L+1)n\log n)\) bits.

Proof. Every nonzero summand contributing to \(S_p(t)\) is of the form \[G_p(t)\,\Delta(A)^2\prod_{a\in A}(t-a)^2G_p(a)\] for some \(L\)-element subset \(A\subseteq[t-1]\) with the prescribed sum. The factorial contribution from the \(L+1\) factors \(G_p(t)\) and \(G_p(a)\) is at most \((n!)^{2(L+1)}\), which has \(O((L+1)n\log n)\) bits.

It remains to bound the difference factors. The Vandermonde term contributes \(\binom{L}{2}\) differences, the prefix–suffix and prefix–\(t\) terms contribute \(rL+r\) differences, and the factors \((t-a)^2\) contribute \(L\) more. The squares only change the constant in the exponent. Every difference has absolute value at most \(n\), so the total contribution of these factors is at most \[n^{O(L^2+rL+r+L)}.\] Because \(r+L+1=k\le n\), we have \[L^2+rL+r+L=O(nL+n),\] so these factors contribute only \(O((L+1)n\log n)\) bits.

Finally, the number of summands is at most \(\binom{t-1}{L}\le \binom nL\). Thus summing the terms increases the bit length by at most \(\log_2\binom nL=O(L\log n)\), which is absorbed by \(O((L+1)n\log n)\). Combining the factorial contribution, the difference factors, and this summation overhead gives the stated bound. ◻

We now explain how these integer completion scores are computed exactly in the word-RAM model. By Lemma 10, every completion score arising at a stage with suffix length \(L\) has \(O((L+1)n\log n)\) bits. Hence, for a sufficiently large absolute constant \(C\), every completion score arising anywhere in the algorithm has at most \[B:=Ckn\log n\] bits.

Let \[d_{\max}:=n(k-1)+1\le n^2+1 .\] All interpolation steps below use at most \(d_{\max}\) evaluation points. We therefore fix a set \(\mathcal{P}\) of distinct \(\Theta(\log n)\)-bit primes, each larger than \(d_{\max}\), such that \(\prod_{\mathfrak p\in\mathcal{P}}\mathfrak p>2^B\).

Since each prime contributes \(\Theta(\log n)\) bits to the product, it is enough to take \(|\mathcal{P}|=\tilde{O}(kn)\) such primes. For each \(\mathfrak p\in\mathcal{P}\), we run the same computation over \(\mathbf{F}_{\mathfrak p}\). Afterwards, each integer completion score is recovered exactly by Chinese remaindering.

In the proofs below we use the following CRT accounting convention. We first count field operations over a single word-size prime field \(\mathbf{F}_{\mathfrak p}\). Since the computation is repeated for \(\tilde{O}(kn)\) primes, this field operation count is then multiplied by \(\tilde{O}(kn)\). The final integer completion scores are recovered by Chinese remaindering.

Lemma 11 (Direct stage oracle). Fix one sampling stage with current prefix \(p\) and suffix length \(L\). If the determinant oracle of Section 4.2 is evaluated separately for each candidate \(t\), then all exact completion scores at that stage can be computed in \[\tilde{O}\!\bigl(n^4kL^3\bigr)\] word operations.

Proof. If \(L=0\), the stage is trivial, so assume \(L\ge 1\). It is enough first to analyse one computation over a word-size prime field \(\mathbf{F}_{\mathfrak p}\), and then multiply the resulting field-operation count by the number \(\tilde{O}(kn)\) of primes used for Chinese remaindering. Since \(\mathfrak p>d_{\max}\ge Ln+1\), the field contains enough distinct evaluation points for interpolation.

Fix a candidate \(t\). Over this field, the polynomial \[D_t(q):=\det M_{L,E_t,\psi_{p,t}}(q)\] has degree at most \(Ln\). Evaluate it at \[d:=Ln+1\] distinct nonzero points and interpolate. Since \(\mathfrak p>d_{\max}\ge d\), the field \(\mathbf{F}_{\mathfrak p}\) contains at least \(d\) nonzero evaluation points. At one evaluation point, forming \(M_{L,E_t,\psi_{p,t}}(\xi)\) directly from its defining sum costs \(O(nL^2)\) field operations, and computing its determinant classically costs \(O(L^3)\) field operations. Since \(L\le n\), the determinant cost is absorbed by \(O(nL^2)\). Thus one candidate costs \[O(d\,nL^2)=O(n^2L^3)\] field operations. The interpolation cost is within the same bound.

There are at most \(n\) candidates, so one stage costs \(O(n^3L^3)\) field operations over a single word-size prime field. Since this computation is repeated for \(\tilde{O}(kn)\) primes, the total cost is \[\tilde{O}(n^4kL^3)\] word operations. Chinese remaindering then recovers the exact integer completion scores. ◻

Lemma 12 (Direct shape-sampling time). The exact shape sampler of Theorem 8 has expected running time \[\tilde{O}\!\bigl(n^4k^5\bigr)\] word operations.

Proof. Along one execution there are exactly \(k\) sampling stages, with suffix lengths \[k-1,k-2,\dots,1,0.\] By Lemma 11, the stage with suffix length \(L\ge 1\) costs \(\tilde{O}(n^4kL^3)\) word operations. Summing over all nontrivial stages gives \[\sum_{L=1}^{k-1}\tilde{O}(n^4kL^3) = \tilde{O}\!\left(n^4k\sum_{L=1}^{k-1}L^3\right) = \tilde{O}(n^4k^5).\] The terminal stage \(L=0\) is trivial. The exact weighted choices require only lower-order arithmetic on \(O(kn\log n)\)-bit integers. The expectation comes from implementing the exact random choices by rejection sampling from power-of-two ranges. ◻

Proof of Theorem 2. Sample the shape distribution using the sequential sampler of Theorem 8, implemented as in Lemma 12. Conditional on the sampled shape \(\lambda\), sample two independent uniform tableaux of shape \(\lambda\) using the Greene–Nijenhuis–Wilf hook walk [28], and apply the inverse Robinson–Schensted correspondence by reverse insertion [27]. By Lemma 9, the output permutation is uniform on \(\Omega_{n,k}\).

The hook-walk sampler uses \(O(n^2)\) hook-walk steps in the worst case. In the random-bit model its exact random choices have expected constant overhead per step, so the two tableau samples have expected running time \(O(n^2)\). The inverse Robinson–Schensted step is deterministic and takes \(O(n^2)\) word operations. These costs are absorbed in the bound above. ◻

6 Speeding up the completion-score oracle↩︎

The direct implementation computes each candidate completion score separately. We now give a faster implementation of the same oracle. The sequential sampler, the completion scores \(S_p(t)\), and the correctness proof (Theorem 8) are unchanged. Only the cost of evaluating the completion scores decreases.

Fix a prefix \(p\), a candidate next coordinate \(t\), and an evaluation point \(\xi\). The polynomial matrix from Lemma 8 becomes \[M_{L,E_t,\psi_{p,t}}(\xi) = \sum_{a<t}(t-a)^2G_p(a)\xi^a\,v(a)v(a)^\top .\] Using zero-based indices \(0\le i,j<L\), its \((i,j)\) entry is \[\sum_{a<t}(t-a)^2G_p(a)\xi^a a^{i+j}.\] Thus the entry depends only on \(i+j\), and so the evaluated matrix is Hankel. Equivalently, it is determined by the \(2L-1\) anti-diagonal quantities corresponding to \(i+j=0,1,\ldots,2L-2\), rather than by all \(L^2\) entries. These anti-diagonal quantities are weighted power sums, and we refer to them as moments.

We use the following structured linear-algebra primitive.

Lemma 13 (Superfast Hankel determinant primitive). Let \(F\) be a field. Given elements \[h_0,h_1,\ldots,h_{2L-2}\in F,\] viewed as the moment sequence defining the Hankel matrix \[H=(h_{i+j})_{0\le i,j<L},\] the determinant \(\det H\) can be computed in \(\tilde{O}(L)\) arithmetic operations in \(F\), without assuming that \(H\) is nonsingular.

Proof. Let \[h(z)=h_0+h_1z+\cdots+h_{2L-2}z^{2L-2}.\] The determinant of the order-\(j\) Hankel matrix depends only on \(h_0,\ldots,h_{2j-2}\). Hence the determinants of orders \(1,\ldots,L\) are determined by the truncation of \(h(z)\) modulo \(z^{2L-1}\).

We apply the algorithm of Liu, Xin and Zhang [29] to this polynomial, regarded as a rational power series with denominator \(1\). Their algorithm computes the initial Hankel determinant sequence \[H_1(h),H_2(h),\ldots,H_L(h)\] in \(O(L\log^2 L)\) field operations, using generalized Sturm sequences and half-GCD computation. Taking the final term of this sequence gives \[H_L(h)=\det(h_{i+j})_{0\le i,j<L}.\]

The algorithm computes the full determinant sequence and returns zero for orders at which the Hankel determinant vanishes. Thus no nonsingularity assumption on the intermediate Hankel matrices, or on \(H\) itself, is needed. ◻

We now describe how the primitive is used at one sampling stage. Fix a prefix \(p\) and suffix length \(L\ge 1\). By the CRT accounting convention of Section 5, the computation is performed over the fixed set \(\mathcal{P}\) of word-size prime fields chosen there. At this stage, the polynomial \(D_t(q)\) has degree at most \(Ln\), so we use \[d:=Ln+1\] distinct nonzero evaluation points for interpolation. Since every \(\mathfrak p\in\mathcal{P}\) is larger than \[d_{\max}=(k-1)n+1\ge d,\] the field \(\mathbf{F}_{\mathfrak p}\) contains enough nonzero evaluation points at every stage.

We first count field operations over a single word-size prime field \(\mathbf{F}_{\mathfrak p}\), for \(\mathfrak p\in\mathcal{P}\). The same computation is then repeated for the \(\tilde{O}(kn)\) primes in \(\mathcal{P}\), and the exact integer completion scores are recovered by Chinese remaindering. Thus an arithmetic bound of \(T\) field operations for one stage gives a \(\tilde{O}(Tkn)\) word-RAM bound.

For a fixed evaluation point \(\xi\in\mathbf{F}_{\mathfrak p}\), define \[m^{(\gamma)}_\ell(t,\xi) := \sum_{a<t} a^{\gamma+\ell}G_p(a)\xi^a, \qquad \gamma=0,1,2, \qquad 0\le \ell\le 2L-2.\] These are the anti-diagonal moments of the cumulative Hankel matrices \[A_\gamma^{(<t)}(\xi) := \sum_{a<t}a^\gamma G_p(a)\xi^a v(a)v(a)^\top, \qquad \gamma=0,1,2.\] Indeed, since \(v(a)v(a)^\top\) has zero-based \((\alpha,\beta)\) entry \(a^{\alpha+\beta}\), the \((\alpha,\beta)\) entry of \(A_\gamma^{(<t)}(\xi)\) is \[\sum_{a<t}a^{\gamma+\alpha+\beta}G_p(a)\xi^a = m^{(\gamma)}_{\alpha+\beta}(t,\xi),\] which depends only on \(\alpha+\beta\).

Using \[(t-a)^2=t^2-2ta+a^2,\] we obtain \[M_{L,E_t,\psi_{p,t}}(\xi) = t^2A_0^{(<t)}(\xi) - 2tA_1^{(<t)}(\xi) + A_2^{(<t)}(\xi).\] Therefore \(M_{L,E_t,\psi_{p,t}}(\xi)\) is Hankel with moment sequence \[h_\ell(t,\xi) = t^2m^{(0)}_\ell(t,\xi) - 2t\,m^{(1)}_\ell(t,\xi) + m^{(2)}_\ell(t,\xi), \qquad 0\le \ell\le 2L-2.\] Writing \[D_t(q):=\det M_{L,E_t,\psi_{p,t}}(q),\] we therefore have \[D_t(\xi) = \det\bigl(h_{\alpha+\beta}(t,\xi)\bigr)_{0\le \alpha,\beta<L}.\]

Lemma 14 (Fast Hankel completion-score oracle). Fix one sampling stage with current prefix \(p\) and suffix length \(L\ge 1\). All exact completion scores at that stage can be computed in \[\tilde{O}\!\bigl(n^3kL^2\bigr)\] word operations.

Proof. We first analyse the computation over one word-size prime field \(\mathbf{F}_{\mathfrak p}\), with \(\mathfrak p\in\mathcal{P}\), and then apply the CRT accounting convention of Section 5.

Before the sweep begins, assume that the array \[\{G_p(a):1\le a\le n\}\] has been computed for the current prefix. This array can be computed from scratch in \(O(nr)\le O(nk)\) field operations, or maintained between successive stages using \[G_{(p,u)}(a)=G_p(a)(u-a)^2\] in \(O(n)\) field operations after the sampled coordinate \(u\) is appended. Since \(L\ge 1\) and \(k\le n\), this cost is absorbed by the \(\tilde{O}(n^2L^2)\) field-operation bound below.

Fix an evaluation point \(\xi\in\mathbf{F}_{\mathfrak p}\). We sweep over \(t=1,\ldots,n\) while maintaining the three moment vectors \[\bigl(m^{(\gamma)}_\ell(t,\xi)\bigr)_{0\le \ell\le 2L-2}, \qquad \gamma=0,1,2.\] Passing from \(t\) to \(t+1\) adds the contribution of \(a=t\): \[m^{(\gamma)}_\ell(t+1,\xi) = m^{(\gamma)}_\ell(t,\xi) + t^{\gamma+\ell}G_p(t)\xi^t .\] All powers of \(t\) up to degree \(2L\) can be generated sequentially, and \(\xi^t\) can be updated by one multiplication as the sweep advances. Since \(G_p(t)\) is available by lookup from the precomputed array, updating all three moment vectors costs \(\tilde{O}(L)\) field operations.

For this value of \(t\), forming the Hankel moments \[h_\ell(t,\xi) = t^2m^{(0)}_\ell(t,\xi) - 2t\,m^{(1)}_\ell(t,\xi) + m^{(2)}_\ell(t,\xi), \qquad 0\le \ell\le 2L-2,\] costs \(O(L)\) field operations. By Lemma 13, the determinant \(D_t(\xi)\) is then computed from these moments in \(\tilde{O}(L)\) field operations. Thus one complete sweep over all candidates \(t\) costs \(\tilde{O}(nL)\) field operations for this fixed evaluation point.

We use \(d=Ln+1\) distinct nonzero evaluation points. Hence all values \[D_t(\xi_u), \qquad 1\le t\le n,\quad 1\le u\le d,\] are computed in \[\tilde{O}(dnL)=\tilde{O}(n^2L^2)\] field operations.

For each fixed \(t\), the polynomial \(D_t(q)\) has degree at most \(Ln=d-1\). Precompute the Lagrange coefficient table \[c_{a,u}:=[q^a]\ell_u(q), \qquad 0\le a<d,\quad 1\le u\le d,\] where \(\ell_u\) is the Lagrange basis polynomial for the chosen evaluation points. This table has size \(d^2\) and can be computed in \(\tilde{O}(d^2)=\tilde{O}(n^2L^2)\) field operations.

For candidate \(t\), the required suffix sum is \[s_t=N-\sum_{i=1}^r p_i-t.\] If \(s_t\notin\{0,\ldots,d-1\}\), then the required coefficient is zero. Otherwise interpolation gives \[[q^{s_t}]D_t(q)=\sum_{u=1}^d c_{s_t,u}D_t(\xi_u).\] Recovering these coefficients for all \(t\) costs \(O(nd)=O(n^2L)\) field operations, which is lower order. Multiplying by the precomputed value \(G_p(t)\) then gives all completion scores \[S_p(t)=G_p(t)[q^{s_t}]D_t(q).\]

The stage therefore costs \(\tilde{O}(n^2L^2)\) field operations over one word-size prime field. By the CRT accounting convention, the same computation is repeated for \(\tilde{O}(kn)\) primes, giving \[\tilde{O}(n^2L^2)\cdot \tilde{O}(kn) = \tilde{O}(n^3kL^2)\] word operations. Chinese remaindering then recovers the exact integer completion scores. ◻

Lemma 15 (Fast shape-sampling time). The exact shape sampler has expected running time \[\tilde{O}\!\bigl(n^3k^4\bigr).\]

Proof. The suffix lengths along one execution are \[k-1,k-2,\ldots,1,0.\] The terminal stage is trivial. By Lemma 14, the stage with suffix length \(L\ge 1\) costs \(\tilde{O}(n^3kL^2)\) word operations. Therefore \[\sum_{L=1}^{k-1}\tilde{O}(n^3kL^2) = \tilde{O}\!\left(n^3k\sum_{L=1}^{k-1}L^2\right) = \tilde{O}(n^3k^4).\] ◻

Proof of Theorem 3. The sampling law is the same as in Theorem 2. Only the implementation of the completion-score oracle changes. By Lemma 15, the shape distribution is sampled in expected \(\tilde{O}(n^3k^4)\) word operations. The subsequent tableau-sampling choices have expected \(O(n^2)\) running time, and the inverse Robinson–Schensted step is deterministic and takes \(O(n^2)\) word operations. Exactness is unchanged, since the same integer completion scores are computed and the same exact weighted choices are made. ◻

References↩︎

[1]
M. L. Fredman, “On computing the length of longest increasing subsequences,” Discrete Mathematics, vol. 11, no. 1, pp. 29–35, 1975, doi: 10.1016/0012-365X(75)90103-X.
[2]
M. Crochemore and E. Porat, “Fast computation of a longest increasing subsequence and application,” Information and Computation, vol. 208, no. 9, pp. 1054–1059, 2010, doi: 10.1016/j.ic.2010.04.003.
[3]
P. Gopalan, T. S. Jayram, R. Krauthgamer, and R. Kumar, “Estimating the sortedness of a data stream,” in Proceedings of the 18th ACM-SIAM symposium on discrete algorithms, 2007, pp. 318–327, doi: 10.5555/1283383.1283417.
[4]
F. Ergün and H. Jowhari, “On distance to monotonicity and longest increasing subsequence of a data stream,” in Proceedings of the 19th ACM-SIAM symposium on discrete algorithms, 2008, pp. 730–736, doi: 10.5555/1347082.1347162.
[5]
M. E. Saks and C. Seshadhri, “Estimating the longest increasing sequence in polylogarithmic time,” SIAM Journal on Computing, vol. 46, no. 2, pp. 774–823, 2017, doi: 10.1137/130942152.
[6]
M. H. Albert, A. Golynski, A. M. Hamel, A. López-Ortiz, S. S. Rao, and M. A. Safari, “Longest increasing subsequences in sliding windows,” Theoretical Computer Science, vol. 321, no. 2–3, pp. 405–414, 2004, doi: 10.1016/j.tcs.2004.03.057.
[7]
A. Chen, T. Chu, and N. Pinsker, “The dynamic longest increasing subsequence problem.” 2013, doi: 10.48550/arXiv.1309.7724.
[8]
M. Mitzenmacher and S. Seddighin, “Dynamic algorithms for LIS and distance to monotonicity,” in Proceedings of the 52nd ACM symposium on theory of computing, 2020, pp. 671–684, doi: 10.1145/3357713.3384240.
[9]
T. Kociumaka and S. Seddighin, “Improved dynamic algorithms for longest increasing subsequence,” in Proceedings of the 53rd ACM symposium on theory of computing, 2021, pp. 640–653, doi: 10.1145/3406325.3451026.
[10]
J. M. Hammersley, “A few seedlings of research,” in Proceedings of the sixth berkeley symposium on mathematical statistics and probability, volume I: Theory of statistics, 1972, pp. 345–394.
[11]
D. Aldous and P. Diaconis, “Hammersley’s interacting particle process and longest increasing subsequences,” Probability Theory and Related Fields, vol. 103, pp. 199–213, 1995, doi: 10.1007/BF01204214.
[12]
B. F. Logan and L. A. Shepp, “A variational problem for random Young tableaux,” Advances in Mathematics, vol. 26, no. 2, pp. 206–222, 1977, doi: 10.1016/0001-8708(77)90030-5.
[13]
A. M. Vershik and S. V. Kerov, “Asymptotics of the Plancherel measure of the symmetric group and the limiting form of Young tableaux,” Soviet Mathematics Doklady, vol. 18, pp. 527–531, 1977.
[14]
K. Johansson, “The longest increasing subsequence in a random permutation and a unitary random matrix model,” Mathematical Research Letters, vol. 5, no. 1, pp. 63–82, 1998, doi: 10.4310/MRL.1998.v5.n1.a6.
[15]
J. Baik, P. Deift, and K. Johansson, “On the distribution of the length of the longest increasing subsequence of random permutations,” Journal of the American Mathematical Society, vol. 12, no. 4, pp. 1119–1178, 1999, doi: 10.1090/S0894-0347-99-00307-0.
[16]
A. Borodin, A. Okounkov, and G. Olshanski, “Asymptotics of Plancherel measures for symmetric groups,” Journal of the American Mathematical Society, vol. 13, no. 3, pp. 481–515, 2000, doi: 10.1090/S0894-0347-00-00337-4.
[17]
A. Okounkov, “Random matrices and random permutations,” International Mathematics Research Notices, vol. 2000, no. 20, pp. 1043–1095, 2000, doi: 10.1155/S1073792800000532.
[18]
D. Aldous and P. Diaconis, “Longest increasing subsequences: From patience sorting to the BaikDeiftJohansson theorem,” Bulletin of the American Mathematical Society, vol. 36, no. 4, pp. 413–432, 1999, doi: 10.1090/S0273-0979-99-00796-X.
[19]
R. P. Stanley, “Increasing and decreasing subsequences and their variants,” in Proceedings of the international congress of mathematicians, madrid, august 22–30, 2006, volume I, 2007, pp. 545–579, doi: 10.4171/022-1/21.
[20]
D. Romik, The surprising mathematics of longest increasing subsequences. Cambridge University Press, 2015.
[21]
H. Thomas and A. Yong, “Longest increasing subsequences, Plancherel-type measure and the Hecke insertion algorithm,” Advances in Applied Mathematics, vol. 46, no. 1–4, pp. 610–642, 2011, doi: 10.1016/j.aam.2009.07.005.
[22]
D. Betea, C. Boutillier, J. Bouttier, G. Chapuy, S. Corteel, and M. Vuletić, “Perfect sampling algorithms for Schur processes,” Markov Processes and Related Fields, vol. 24, no. 3, pp. 381–418, 2018, [Online]. Available: https://arxiv.org/abs/1407.3764.
[23]
C. Schensted, “Longest increasing and decreasing subsequences,” Canadian Journal of Mathematics, vol. 13, pp. 179–191, 1961, doi: 10.4153/CJM-1961-015-3.
[24]
J. S. Frame, G. de B. Robinson, and R. M. Thrall, “The hook graphs of the symmetric group,” Canadian Journal of Mathematics, vol. 6, pp. 316–324, 1954, doi: 10.4153/CJM-1954-030-1.
[25]
K. Johansson, “Discrete orthogonal polynomial ensembles and the plancherel measure,” Annals of Mathematics, vol. 153, no. 1, pp. 259–296, 2001.
[26]
R. A. Horn and C. R. Johnson, Matrix analysis, 2nd ed. Cambridge University Press, 2013.
[27]
B. E. Sagan, The symmetric group: Representations, combinatorial algorithms, and symmetric functions, 2nd ed., vol. 203. New York: Springer, 2001.
[28]
C. Greene, A. Nijenhuis, and H. S. Wilf, “A probabilistic proof of a formula for the number of Young tableaux of a given shape,” Advances in Mathematics, vol. 31, no. 1, pp. 104–109, 1979, doi: 10.1016/0001-8708(79)90023-9.
[29]

  1. Throughout, exact weighted choices are made as follows. Given nonnegative integer weights \(w_1,\dots,w_M\) with sum \(W\), we draw a uniform integer from \(\{1,\dots,W\}\) by rejection sampling from a power-of-two range and select the corresponding interval in the cumulative sums. This costs expected \(O(\log W)\) random bits and arithmetic quasilinear in the bit length of \(W\).↩︎