For a permutation input, the first row of its RSK insertion tableau is the minimum-tail table for increasing subsequences: its th entry is the least attainable final value of a strictly increasing subsequence of length in the processed prefix. Inserting replaces the first entry larger than , or appends if none exists. In replacement position , the previous entry in position supplies a subsequence that can be extended by . Shorter minimum tails were already smaller, and a longer subsequence ending at would require an old tail in position at least smaller than , contrary to the replacement rule. This proves the invariant inductively. Consequently the first-row length is the longest increasing subsequence length. The row entries need not be a subsequence together: input gives first row , although one occurs after three. They are minima for different lengths, obtained from potentially different subsequences.
Increasing subsequence Created 2026-09-28 Updated 2026-10-13
An increasing subsequence of a finite sequence in a totally ordered set selects indices such that
Here “increasing” means weakly increasing, also called nondecreasing: equal values are allowed, but indices must increase strictly. This is the convention of [ref]. A strictly increasing subsequence instead requires . Always check which convention an algorithm uses, especially when values repeat.
An increasing subsequence may skip positions; it neither rearranges values nor requires consecutive positions. Consider the deliberately constructed example
The indices select , an increasing subsequence of length four. The indices select , a strictly increasing subsequence of length three. In contrast, rearranges the input and is not a subsequence. The longest consecutive nondecreasing block is , of length three; requiring consecutive positions would therefore solve a different problem.
Think of an increasing subsequence as preserving ordered observations while skipping interruptions. For the example, discarding leaves four observations with no downward step. The longest increasing subsequence asks how much of the original order can be kept. This is an order comparison, rather than a claim about the size of upward or downward changes: replacing all values by their squares when the values are nonnegative leaves every allowed selection unchanged. More generally, any strictly order-preserving relabeling has this property.
For the longest increasing subsequence length on a product space of independent coordinates, a witness of length uses only coordinates. Any point with subsequence length at most must differ on at least witness positions. Weights on those positions show . Thus for ,
At a median , this gives upper tail and lower tail . Integrating the tails places the mean within of the median, so the natural concentration scale near the mean is . A random permutation is represented by the ranks of independent continuous variables; arbitrary dependent sequences need not obey this conclusion.
Longest increasing subsequence Created 2026-09-28 Updated 2026-10-14
A longest increasing subsequence is an increasing subsequence of maximum length. Write that length as , with for the empty sequence; a nonempty input has . Several selections can attain the same maximum. Here uses the weak convention ; write for the maximum length of a strictly increasing subsequence. For , these lengths are three and one respectively; for an input with distinct values they agree.
For , the answer is , attained at indices , while . One useful interpretation is the smallest number of deletions needed to make the surviving sequence nondecreasing:
Indeed, keeping a longest increasing subsequence attains this bound, and any valid remaining sequence is an increasing subsequence, so cannot have more than terms. In this example the answer is . This makes a measure of how much order can be recovered without moving any observation.
A table that ends at each position. Let be the maximum length of an increasing subsequence ending specifically at position . The dynamic programming recurrence relation is
The zero covers a selection consisting only of . Otherwise its penultimate index is an eligible ; append to an optimal selection ending there. Fill entries in increasing index order. For strictly increasing subsequences, change the comparison to . The strict version and reconstruction are developed in University of Toronto, CSC373 tutorial 4 solutions (2018), exercise 2; the weak version follows by allowing equality at the append step.
In the worked input, the weak table is and the strict table is . At the second , equality extends the first in the weak table. The final entry is only one, although the optimum is four: the best increasing subsequence need not finish at the last input position. Record a maximizing predecessor whenever . Following these stored indices from any position maximizing , then reversing them, gives an actual longest increasing subsequence. For the weak example the backward chain is .
Figure 1.
Skipping positions and allowing equal values changes the optimum
. An original toy input, not measured data. The colored selection keeps indices and values . The two dynamic programming rows give the best lengths ending at every position; the backward arrows reconstruct the weak longest increasing subsequence. Details.
Scanning all earlier positions for each uses time complexity and space complexity for lengths and predecessors, using Big O notation and assuming constant-time comparisons and operations on indices.
Keep the easiest ending to extend. The faster algorithm maintains a minimum-tail table for increasing subsequences: is the smallest final value of any length- increasing subsequence in the processed prefix. For equal lengths, a smaller ending permits every future extension allowed by a larger ending. Thus only one best ending per length is needed. The table is nondecreasing, since removing the last term of a length- selection gives . Start with an empty table. On reading , use binary search to find the first entry strictly greater than : replace it by , or append if there is no such entry. Its position is one beyond the longest existing length whose ending is at most . See Liben-Nowell, Vee and Zhu, section 3.1 and Figure 1.
Duplicates determine the binary search rule: weak increase replaces the first , whereas strict increase replaces the first . In Python these positions are returned by bisect_right(T, v) and bisect_left(T, v) respectively, counting positions from zero. Replace an entry or append; do not insert and shift the remaining entries. The documented equality rules are in Python documentation, bisect_left and bisect_right. Each search takes comparisons, giving time complexity , conventionally for , and space complexity for the weak length alone.
Figure 2.
Two binary-search tie rules give different minimum-tail tables
. Original exact traces for the same toy input, not measured data. Each cell shows a tail value and the input index supplying it; the outlined cell was updated in that row. At the second , the weak algorithm appends and the strict algorithm replaces. The final weak table has length four, but its supplier indices are not in increasing order. Details.
A length certificate needs separate reconstruction. The final weak tail values are , but they do not form an increasing subsequence of this input: the zero occurs last. Each table entry certifies a selection of its own length; the entries need not come from one compatible selection. To recover a longest increasing subsequence during the fast algorithm, store a supplier index for each tail and a predecessor index for each input position. Before replacing slot , save , or no predecessor if , then set . Later replacements leave saved unchanged. Follow predecessors from the final and reverse. This uses space complexity and returns indices for the weak trace. The same construction works with the strict comparator; compare the two auxiliary arrays in CP Algorithms contributors, restoring the subsequence after binary search.
Deleting or changing one term. If deletes position , then
Deleting cannot create a longer increasing subsequence; removing position from a previously optimal selection loses at most one term. If instead changes just the value at position , both inputs have the same deleted sequence, so their lengths each lie between its length and its length plus one. Consequently . These bounds also hold for strictly increasing subsequences. In the weak example, deleting either lowers the length to three, while deleting the final zero leaves it four. This is a Lipschitz bound for single-term edits, regardless of the numerical size of a replacement. Insertion has the same bound by reversing deletion, so insertions, deletions or replacements can change by at most .
For historical context, [ref] studies the comparison count for distinct elements of a totally ordered set. Its distinctness assumption makes the weak and strict conventions coincide. No distinctness assumption is needed for the comparator-specific algorithms above.
For a processed prefix , the minimum-tail table for increasing subsequences stores
There is no slot for an unattainable length. The table records minimum endings, rather than the terms of one longest increasing subsequence. Replacing the value comparisons by gives the corresponding table for strictly increasing subsequences, whose entries are strictly increasing.
For and nonempty , let
The Talagrand convex distance is
Equivalently,
For completeness, let be a closest point of the finite convex hull to zero. If , minimality gives for every . Taking proves that the supremum is at least . Conversely each permitted has by Cauchy-Schwarz. The weights are nonnegative because the hull has nonnegative coordinates. If , both sides are zero. This proves the dual definition used below.
We prove Talagrand's convex distance inequality by induction on the number of factors. Write , with measure , and . For a last-coordinate value , let . Choose a section of largest probability , and put . The total event probability is .
If has positive probability, combine mismatch vectors from and from . A weight on the second section contributes at most in the last coordinate. Convexity of the squared Euclidean norm gives, for every ,
The last-coordinate contribution is actually zero if , so the displayed upper bound remains valid. Hölder's inequality and the induction hypothesis yield
For a zero-probability section use directly, so no division by zero or exponent of an infinite quantity is needed.
The scalar estimate for Talagrand product induction is
Here is its proof. For set . If , take ; the logarithm of the left expression is . Put . Then and
since for . Thus . If , choose . The already proved boundary case gives . The same direct choice covers .
Average the resulting section bounds over :
where the last inequality is equivalent to . The induction starts on the zero-coordinate singleton, where every positive-probability event is the whole space and the moment is one. Hence
We assume ; a zero-probability event has no finite right-hand bound to prove. Markov's inequality also gives
For the subsequence application, let be the longest increasing subsequence length for independent sequence coordinates. A witness of length uses only positions. If and satisfies , at least witness positions must change: all unchanged witness positions remain in increasing order. Put weights on the witness and zero elsewhere. The dual distance definition gives
where the latter expression increases with for . Therefore the increasing-subsequence certificate concentration bound is
If the lower event has probability zero the conclusion is immediate.
Let be an integer median, so . Taking the two thresholds in the bound gives, for ,
For the lower event is empty. In a nonempty sequence . Integration of these tails gives an explicit mean-median estimate: use for and for , obtaining
Writing , the median property also gives . Consequently, for a universal constant , all satisfy
Thus the subsequence length is concentrated near its mean on the scale , rather than the generic coordinate-exposure scale . This argument applies directly to finite-valued independent sequences. Independent continuous samples follow by refining finite coordinate discretizations; the strict-order pattern stabilizes almost surely when ties have probability zero. A uniform random permutation is the rank sequence of independent continuous samples, so it has the same subsequence-length concentration. Arbitrarily dependent random sequences are not covered by the product-space assumption.
Every old box either remains untouched or has its entry replaced by a strictly smaller incoming value. Thus on all boxes of the original diagram,
The appended box has no old entry to compare; equivalently, extend the old filling by outside its diagram if the inequality is to be written for every position.
We now prove the unheaded longest increasing subsequence assertion. After any prefix of the permutation has been inserted, write the first-row entries as . The useful invariant is: is the smallest possible final value of an increasing subsequence of length in that prefix, and is the greatest possible subsequence length. It holds for the empty prefix.
Suppose the next letter enters the first row in column . Then , if , while if column already exists. A subsequence of length ending at can be extended by , giving a subsequence ending at of length ; for , the singleton suffices. A longer subsequence ending at would have an earlier length- prefix ending below , contradicting the minimality of . If , the previous prefix has no subsequence longer than , giving the same upper bound.
Replacing by , or appending it at , preserves the invariant. It lowers the smallest final value at length . At smaller lengths, existing minima are already below , so they cannot improve; no subsequence of greater length can end at . The lower rows do not change this first-row update. Induction proves that the longest increasing subsequence ending in has length exactly the column in which first enters.
Taking the maximum over all letters gives Schensted's first-row theorem:
This concerns the column of the incoming letter in the first row, not the column of the new box that eventually appears at the end of the bumping path.
Fix every coordinate except . As varies, the longest increasing subsequence length can change by at most one: deleting the changed term leaves a common subsequence of length at least the larger value minus one. The conditional range therefore has length at most one, so the Popoviciu inequality on variances gives
The coordinatewise conditional-variance form of the Efron–Stein inequality now yields
Replacing one input coordinate changes the longest increasing subsequence length by at most one, so has the bounded differences property with . The two-sided McDiarmid inequality gives, for ,
Patience sorting Created 2026-10-20 Updated 2026-11-05
Patience sorting processes values into piles by putting each next value on the leftmost pile whose top is at least that value, creating a new pile when none qualifies. The pile tops stay increasing, so binary search finds the destination. The number of piles equals the length of a longest increasing subsequence: each pile is nonincreasing in arrival order, while predecessor links across piles construct an increasing subsequence of that length. For 3,1,2,4, the tops evolve to 1,2,4, giving length three. Changing the comparison changes whether equality is allowed in the subsequence. Merging the completed piles can then produce a full sorted output.[ref]
Robinson–Schensted correspondence Created 2026-10-06 Updated 2026-10-07
Insert the successive letters of a permutation by row insertion to obtain an insertion tableau , recording the insertion times in the new boxes of . This is a bijection between permutations and pairs of standard Young tableaux of a common shape. Reverse insertion removes the box marked by the latest recording time. The first row of has length equal to the longest increasing subsequence.
A strictly increasing subsequence selects indices of a sequence with . Equal values cannot both occur in it. Its maximum possible length is , with ; in general for the weak longest increasing subsequence. Use strict comparisons in the dynamic programming recurrence relation and replace the first tail at least as large as the next value in the binary search algorithm.