Skip to content

LongestDecreasingSubsequence ​

The length of a longest decreasing subsequence.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaLongest increasing subsequenceWikidataQ4183855FindStatSt000760via IntegerComposition✓
LongestDecreasingSubsequence(p)The length of a longest decreasing subsequence.
Typed signatures
TypePackageApplies
(composition | 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.
  • The same fold with the comparison reversed — by Dilworth, the number of piles when the tops are kept decreasing.

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))

on IntegerComposition, over _x

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

Examples

Basic #

the one-line word 312312

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

the one-line word 312312, as a plain list

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

the one-line word 24132413

live ↗
InLongestDecreasingSubsequence(Permutation⁡([2,4,1,3]))\mathrm{LongestDecreasingSubsequence}({\operatorname{Permutation}}([2, 4, 1, 3]))Out22
About
Examples3
CrosswalkWikipediaWikidataFindStat