Skip to content

LongestIncreasingSubsequence ​

The length of a longest increasing subsequence.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaLongest increasing subsequenceWikidataQ4183855FindStatSt000062via Permutation✓Rosetta CodeLongest increasing subsequence
LongestIncreasingSubsequence(p)The length of a longest increasing subsequence.
CombinatoricaLength[LongestIncreasingSubsequence[p]]SageMathenumeratio_stat("Permutation", p, "LongestIncreasingSubsequence")
Typed signatures
TypePackageApplies
(list<integer> | permutation) -> numbercombinatoricsalways

Domain: Permutation statistics

Details
  • Defined over Permutation as an expression in _x, evaluated by compute-engine — the definition IS the implementation.
  • Takes a Permutation, and also a bare list of integers: this reading compares entries with each other rather than with their positions, so it stands on any sequence.
  • By patience sorting: the number of piles. Checked against the piles algorithm over every permutation of 1..6.

Definition

Epsil, as the implementation runs it.

on Permutation, over _x

0 if Length(_x) < 1 else Count(Fold(Function(Apply(
                                                    Function(
                                                              Join(a, [b]) if k >
                                                                              Count(a) else ReplaceAt(a, k, b),
                                                              k,
                                                            ),
                                                    Count(Filter(
                                                                  a,
                                                                  Function(
                                                                            t <
                                                                            b,
                                                                            t,
                                                                          ),
                                                                )) + 1,
                                                  ), a, b), [], _x))

Examples

Basic #

the one-line word 312312

live ↗
InLongestIncreasingSubsequence(Permutation⁡([3,1,2]))\mathrm{LongestIncreasingSubsequence}({\operatorname{Permutation}}([3, 1, 2]))Out22

the one-line word 312312, as a plain list

live ↗
InLongestIncreasingSubsequence([3,1,2])\mathrm{LongestIncreasingSubsequence}(\bigl\lbrack3, 1, 2\bigr\rbrack)Out22

the one-line word 24132413

live ↗
InLongestIncreasingSubsequence(Permutation⁡([2,4,1,3]))\mathrm{LongestIncreasingSubsequence}({\operatorname{Permutation}}([2, 4, 1, 3]))Out22
Properties #

FindStat's value for [1]

live ↗
InCombinatorialStat(Permutation⁡([1]),LongestIncreasingSubsequence)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([1]), \text{LongestIncreasingSubsequence})Out11

Known value · FindStat St000062

FindStat's value for [1,2]

live ↗
InCombinatorialStat(Permutation⁡([1,2]),LongestIncreasingSubsequence)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([1, 2]), \text{LongestIncreasingSubsequence})Out22

Known value · FindStat St000062

FindStat's value for [2,1]

live ↗
InCombinatorialStat(Permutation⁡([2,1]),LongestIncreasingSubsequence)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([2, 1]), \text{LongestIncreasingSubsequence})Out11

Known value · FindStat St000062

About
Examples6
Checked againstCombinatorica 3 agreeSageMath 6 agree
CrosswalkWikipediaWikidataFindStatCombinatoricaSageMathRosetta Code

Implementation

mappedcombinatoricapackages/oracle/src/mappings.ts

Combinatorica returns a longest subsequence; ours is its length.

mappedsagepackages/oracle/src/mappings.ts