Lehmer code: Difference between revisions

Content deleted Content added
removed improper bolding as per MOS:BOLD
Adding short description: "Scheme for numbering permutations"
 
(6 intermediate revisions by 5 users not shown)
Line 1:
{{Short description|Scheme for numbering permutations}}
In [[mathematics]] and in particular in [[combinatorics]], the '''Lehmer code''' is a particular way to [[encoding|encode]] each possible [[permutation]] of a sequence of ''n'' numbers. It is an instance of a scheme for [[Permutation#Numbering permutations|numbering permutations]] and is an example of an [[inversion (discrete mathematics)|inversion]] table.
 
The Lehmer code is named in reference to [[DerrickD. HenryH. Lehmer]],<ref name="lehmer"/> but the code had been known since 1888 at least.<ref name="lehmer"/><ref name="laisant"/>
 
==The code==
The Lehmer code makes use of the fact that there are
:<math>n!=n\times(n-1)\times\cdots\times2\times1</math>
permutations of a sequence of ''n'' numbers. If a permutation ''σ'' is specified by the sequence (''σ''<sub>1</sub>, ..., ''σ''<sub>''n''</sub>'') of its images of 1, ..., ''n'', then it is encoded by a sequence of ''n'' numbers, but not all such sequences are valid since every number must be used only once. By contrast the encodings considered here choose the first number from a set of ''n'' values, the next number from a fixed set of {{math|''n'' − 1}} values, and so forth decreasing the number of possibilities until the last number for which only a single fixed value is allowed; ''every'' sequence of numbers chosen from these sets encodes a single permutation. While several [[encoding]]s can be defined, the Lehmer code has several additional useful properties; it is the sequence
:<math>L(\sigma)=(L(\sigma)_1,\ldots,L(\sigma)_n)\quad\text{where}\quad L(\sigma)_i=\#\{ j>i : \sigma_j<\sigma_i \},</math>
in other words the term ''L''(''σ'')<sub>''i''</sub> counts the number of terms in (''σ''<sub>1</sub>, ..., ''σ''<sub>''n''</sub>'') to the right of ''σ''<sub>''i''</sub>'' that are smaller than it, a number between 0 and {{math|''n'' − ''i''}}, allowing for {{math|''n'' + 1 − ''i''}} different values.
 
A pair of indices (''i'',''j'') with {{math|''i'' &lt; ''j''}} and {{math|''σ''<sub>''i''</sub>'' &gt; ''σ''<sub>''j''</sub>''}} is called an inversion of ''σ'', and ''L''(''σ'')<sub>''i''</sub> counts the number of inversions (''i'',''j'') with ''i'' fixed and varying ''j''. It follows that {{math|''L''(''σ'')<sub>1</sub> + ''L''(''σ'')<sub>2</sub> + … + ''L''(''σ'')<sub>''n''</sub>}} is the total number of inversions of ''σ'', which is also the number of adjacent transpositions that are needed to transform the permutation into the identity permutation. Other properties of the Lehmer code include that the [[lexicographical order]] of the encodings of two permutations is the same as that of their sequences (''σ''<sub>1</sub>, ..., ''σ''<sub>''n''</sub>''), that any value 0 in the code represents a right-to-left minimum in the permutation (i.e., a {{math|''σ''<sub>''i''</sub>''}} smaller than any {{math|''σ''<sub>''j''</sub>''}} to its right), and a value {{math|''n'' − ''i''}}
at position ''i'' similarly signifies a right-to-left maximum, and that the Lehmer code of ''σ'' coincides with the [[factorial number system]] representation of its position in the list of permutations of ''n'' in lexicographical order (numbering the positions starting from 0).
 
Variations of this encoding can be obtained by counting inversions (''i'',''j'') for fixed ''j'' rather than fixed ''i'', by counting inversions with a fixed smaller ''value'' {{math|''σ''<sub>''j''</sub>''}} rather than smaller index ''i'', or by counting non-inversions rather than inversions; while this does not produce a fundamentally different type of encoding, some properties of the encoding will change correspondingly. In particular counting inversions with a fixed smaller value {{math|''σ''<sub>''j''</sub>''}} gives the inversion table of ''σ'', which can be seen to be the Lehmer code of the inverse permutation.
 
==Encoding and decoding==
 
The usual way to prove that there are ''n''! different permutations of ''n'' objects is to observe that the first object can be chosen in {{math|''n''}} different ways, the next object in {{math|''n'' − 1}} different ways (because choosing the same number as the first is forbidden), the next in {{math|''n'' − 2}} different ways (because there are now 2 forbidden values), and so forth. Translating this freedom of choice at each step into a number, one obtains an encoding algorithm, one that finds the Lehmer code of a given permutation. One need not suppose the objects permuted to be numbers, but one needs a [[total ordering]] of the set of objects. Since the code numbers are to start from 0, the appropriate number to encode each object ''σ''<sub>''i''</sub>'' by is the number of objects that were available at that point (so they do not occur before position ''i''), but which are smaller than the object ''σ''<sub>''i''</sub>'' actually chosen. (Inevitably such objects must appear at some position {{math|''j'' &gt; ''i''}}, and (''i'',''j'') will be an inversion, which shows that this number is indeed ''L''(''σ'')<sub>''i''</sub>.)
 
This number to encode each object can be found by direct counting, in several ways (directly counting inversions, or correcting the total number of objects smaller than a given one, which is its sequence number starting from 0 in the set, by those that are unavailable at its position). Another method which is in-place, but not really more efficient, is to start with the permutation of {0, 1, ... {{math|''n'' − 1}}} obtained by representing each object by its mentioned sequence number, and then for each entry ''x'', in order from left to right, correct the items to its right by subtracting 1 from all entries (still) greater than ''x'' (to reflect the fact that the object corresponding to ''x'' is no longer available). Concretely a Lehmer code for the permutation B,F,A,G,D,E,C of letters, ordered alphabetically, would first give the list of sequence numbers 1,5,0,6,3,4,2, which is successively transformed
Line 38 ⟶ 39:
=== Independence of relative ranks ===
 
The Lehmer code defines a bijection from the [[symmetric group]] ''S''<sub>''n''</sub>'' to the Cartesian product <math>[n]\times[n-1]\times\cdots\times[2]\times[1]</math>, where [''k''] designates the ''k''-element set <math>\{0,1,\ldots,k-1\}</math>. As a consequence, under the [[Uniform distribution (discrete)|uniform distribution]] on ''S''<sub>''n''</sub>'', the component ''L''(''σ'')<sub>''i''</sub> defines a uniformly distributed [[random variable]] on {{math|[''n'' − ''i'']}}, and these random variables are mutually [[Independence (probability theory)|independent]], because they are projections on different factors of a [[Cartesian product]].
 
=== Number of right-to-left minima and maxima ===
Line 63 ⟶ 64:
This is an optimal stop problem, a classic in decision theory, statistics and applied probabilities, where a random permutation is gradually revealed through the first elements of its Lehmer code, and where the goal is to stop exactly at the element k such as σ(k)=n, whereas the only available information (the k first values of the Lehmer code) is not sufficient to compute σ(k).
 
In less mathematical words : a series of n applicants are interviewed one after the other. The interviewer must hire the best applicant, but must make his decision (“Hire” or “Not hire”) on the spot, without interviewing the next applicant (and ''a fortiori'' without interviewing all applicants).
 
The interviewer thus knows the rank of the k<sup>th</sup> applicant, therefore, at the moment of making his k<sup>th</sup> decision, the interviewer knows only the k first elements of the Lehmer code whereas he would need to know all of them to make a well informed decision.
Line 71 ⟶ 72:
 
==Similar concepts==
TwoSeveral similarrelated vectorsconstructions arehave inalso been put into use. One of them is often called inversion vector, e.g. by [[Wolfram Alpha]].
 
Two similar vectors are in use. One of them is often called inversion vector, e.g. by [[Wolfram Alpha]].
See also {{Section link|Inversion_(discrete_mathematics)|Inversion related vectors}}.
 
Line 79:
==References==
{{Reflist|refs=
<ref name="lehmer">
{{Citation
| last=Lehmer
| first=D.H.
| title=Combinatorial Analysis
| chapter=Teaching combinatorial tricks to a computer
| series=Proceedings of Symposia in Applied Mathematics
| journal=Proc. Sympos. Appl. Math. Combinatorial Analysis, Amer. Math. Soc.
| author-link=D. H. Lehmer
| volume=10
| year=1960
| pages=179–193
| doi=10.1090/psapm/010/0113289
| isbn=978-0-8218-1310-2
| mr=0113289
}}
</ref>
Line 96 ⟶ 101:
| last=Laisant
| first=Charles-Ange
| author-link= Charles-Ange Laisant
| title=Sur la numération factorielle, application aux permutations
| trans-title=On factorial numbering, application to permutations
| journal=Bulletin de la Société Mathématique de France
| volume=16
| issue=<!--1 of 1-->
| year=1888
| pages=176–183
| url=http://www.numdam.org/item?id=BSMF_1888__16__176_0
| doi=10.24033/bsmf.378
}}
</ref>
Line 109 ⟶ 117:
| last=Ferguson
| first=Thomas S.|authorlink= Thomas S. Ferguson
| title=Who solved the secretary problem ?
| journal=Statistical Science
| volume=4
| issue=3
| yeardate=August 1989
| pages=282–289
| jstor=2245639
| doi=10.1214/ss/1177012493
| doi-access=free
| url=https://www2.math.upenn.edu/~ted/210F10/References/Secretary.pdf
}}
</ref>
Line 141 ⟶ 150:
*{{ Citation
| last1=Knuth
| first1=DonDonald
| author-link=Donald Knuth
| title=The artArt of computerComputer programmingProgramming
| volume=3
| publisher=Addison-Wesley