alih ballon d'or
orderings of the 3-subsets of (and the corresponding binary vectors)when the (blue) triples are in lex order the (red) vectors are in revlex order, and vice versa.
the arrangements on the right side show colex and revcolex order.
dalam matematika, urutan leksikografik, (biasa dikenal sebagai urutan leksikal atau urutan alfabet, adalah bentuk umum dari urutan alfabet kata yang berdasarkan pada pengurutan huruf depan.
diberikan dua himpunan terurut sebagian yaitu a dan b,. leksikografik urutan di dalam cartesian product a  b is defined as
(a,b)  (a,b) if and only if a < a or (a = a and b  b).
the result is a partial order.
if a and b are totally ordered, then the result is a total order as well.
more generally, one can define the lexicographic order on the cartesian product of n ordered sets, on the cartesian product of a countably infinite family of ordered sets, and on the union of such sets.
motivation and uses
the name of the lexicographic order comes from its generalizing the order given to words in a dictionary: a sequence of letters (that is, a word)
a1a2 ... ak
appears in a dictionary before a sequence
b1b2 ... bk
if and only if the first ai, which is different from bi, comes before bi in the alphabet.
that comparison assumes both sequences are the same length.
to ensure they are the same length, the shorter sequence is usually padded at the end with enough "blanks" (a special symbol that is treated as coming before any other symbol).
this also allows ordering of phrases.
for the purpose of dictionaries, etc., padding with blank spaces is always done.
see alphabetical order.
for example, the word "thomas" appears before "thompson" in dictionaries because the letter 'a' comes before the letter 'p' in the alphabet.
the 5th letter is the first that is different in the two words; the first 4 letters are "thom" in both.
because it is the first difference, the 5th letter is the most significant difference (for an alphabetical ordering).
a lexicographical ordering may not coincide with conventional alphabetical ordering.
for example, the numerical order of unicode codepoints does not always correspond to traditional alphabetic orderings of the characters, which vary from language to language.
so the lexicographic ordering induced by codepoint value sorts strings in an unambiguous canonical order, but it does not necessarily "alphabetize" them in the conventional sense.
an important property of the lexicographical order is that it preserves well-orders, that is, if a and b are well-ordered sets, then the product set a  b with the lexicographical order is also well-ordered.
an important exploitation of lexicographical ordering is expressed in the iso 8601 date formatting scheme, which expresses a date as yyyy-mm-dd.
this date ordering lends itself to straightforward computerized sorting of dates such that the sorting algorithm does not need to treat the numeric parts of the date string any differently from a string of non-numeric characters, and the dates will be sorted into chronological order.
note, however, that for this to work, there must always be four digits for the year, two for the month, and two for the day, so for example single-digit days must be padded with a zero yielding '01', '02', ..., '09'.
another example of digits ordered lexicographically is 101,102,103,104,105,106,107,108,109,110,111,112... 200, 201, 202 etc.
another generalization of lexical ordering occurs in social choice theory (the theory of elections).
consider an election in which there are 4 candidates a, b, c and d, each voter expresses a top-to-bottom ordering of the candidates, and the voters' orderings are as follows:
the minmax voting method is a simple condorcet method that counts the votes as in a round-robin tournament (all possible pairings of candidates) and judges each candidate according to its largest "pairwise" defeat.
the winner is the candidate whose largest defeat is the smallest.
in the example:
the largest defeat of a is by d: 65% (33%+32%) rank d over a.
the largest defeat of b is by d: 65% (33%+32%) rank d over b.
the largest defeat of c is by a (or b): 67% (18%+17%+32%) rank a over c (and b over c).
the largest defeat of d is by c: 68% (18%+17%+33%) rank c over d.
minmax declares a tie between a and b since the largest defeats for both are the same size, 65%.
this is like saying "thomas" and "thompson" should be at the same position because they have the same first letter.
however, if the defeats are compared lexically, we have the minlexmax method.
with minlexmax, because the largest defeats of a and b are the same size, their next largest defeats are then compared:
a's next largest defeat is 0%. (this is a padding, since a has only one defeat.)
b's next largest defeat is by a: 51% (18%+33%) rank a over b.
since b's next largest defeat is larger than a's, minlexmax elects a, which makes more sense than the minmax tie since a majority rank a over b.
another usage in social choice theory is the ranked pairs voting method.
although usually defined by a procedure that constructs the order of finish, ranked pairs is equivalent to finding which of all possible orders of finish is best according to a minlexmax comparison of the majorities they reverse.
in the example above, the ranked pairs order of finish is abcd (which elects a). abcd affirms the majorities who rank a over b, a over c, b over c and c over d, and reverses the majorities who rank d over a and d over b. the largest majority that abcd reverses is 65%.
the only other ordering that wouldn't reverse a larger majority is bacd (which also reverses 65%).
abcd is a better order of finish than bacd because the lexically relevant set of majoritiesthe majorities on which abcd and bacd disagreeis {a over b} and bacd reverses the largest majority in this set.
case of multiple products
is an n-tuple of sets, with respective total orderings
the dictionary ordering
that is, if one of the terms
and all the preceding terms are equal.
represents the first letter,
the second and so on when looking up a word in a dictionary, hence the name.
this could be more elegantly stated by recursively defining the ordering of any set
this will satisfy
to put it more simply, compare the first terms.
if they are equal, compare the second terms  and so on.
the relationship between the first corresponding terms that are not equal determines the relationship between the entire elements.
groups and vector spaces
if the component sets are ordered groups then the result is a non-archimedean group, because e.g. n(0,1) < (1,0) for all n.
if the component sets are ordered vector spaces over r (in particular just r), then the result is also an ordered vector space.
ordering of sequences of various lengths
given a partially ordered set a, the above considerations allow to define naturally a lexicographical partial order over the free monoid a* formed by the set of all finite sequences of elements in a, with sequence concatenation as the monoid operation, as follows:
is a prefix of , or
and , where is the longest common prefix of and , and are members of a such that , and and are members of a*.
if < is a total order on a, then so is the lexicographic order <d on a*. if a is a finite and totally ordered alphabet, a* is the set of all words over a, and we retrieve the notion of dictionary ordering used in lexicography that gave its name to the lexicographic orderings.
however, in general this is not a well-order, even though it is on the alphabet a; for instance, if a = {a, b}, the languageanbsimilarly we can also compare a finite and an infinite string, or two infinite strings.
comparing strings of different lengths can also be modeled as comparing strings of infinite length by right-padding finite strings with a special value that is less than any element of the alphabet.
this ordering is the ordering usually used to order character strings, including in dictionaries and indexes.
the quasi-lexicographic order on the free monoid a over an ordered alphabet a orders strings firstly by length, so that the empty string comes first, and then within strings of fixed length n, by lexicographic order on an.
consider the set of functions f from a well-ordered set x to a totally ordered set y. for two such functions f and g, the order is determined by the values for the smallest x such that f(x)  g(x).
if y is also well-ordered and x is finite, then the resulting order is a well-order.
as already shown above, if x is infinite this is in general not the case.
if x is infinite and y has more than one element, then the resulting set yx is not a countable set, see also cardinal exponentiation.
alternatively, consider the functions f from an inversely well-ordered x to a well-ordered y with minimum 0, restricted to those that are non-zero at only a finite subset of x. the result is well-ordered.
correspondingly we can also consider a well-ordered x and apply lexicographical order where a higher x is a more significant position.
this corresponds to exponentiation of ordinal numbers yx. if x and y are countable then the resulting set is also countable.
in algebra it is traditional to order terms in a polynomial, by ordering the monomials in the indeterminates.
this is fundamental, to have a normal form.
such matters are typically left implicit in discussion between humans, but must of course be dealt with exactly in computer algebra.
in practice one has an alphabet of indeterminates x, y, ... and orders all monomials formed from them by a variant of lexicographical order.
for example if one decides to order the alphabet by
x < y < ...
and also to look at higher terms first, that means ordering
... < x3 < x2 < x
x < yk for all k.
there is some flexibility in ordering monomials, and this can be exploited in grbner basis theory.
for decimal fractions from the decimal point, a < b applies equivalently for the numerical order and the lexicographic order, provided that numbers with a recurring decimal 9 like .399999... are not included in the set of strings representing numbers.
with that restriction there is an order-preserving bijection between the strings and the numbers.
reverse lexicographic order
in a common variation of lexicographic order, one compares elements by reading from the right instead of from the left, i.e., the right-most component is the most significant, e.g. applied in a rhyming dictionary.
in the case of monomials one may sort the exponents downward, with the exponent of the first base variable as primary sort key, e.g.:
alternatively, sorting may be done by the sum of the exponents, downward.
orders on the cartesian product of totally ordered sets
lexicographic order on the rn
lexicographic order topology on the unit square
long line (topology)
lexicographically minimal string rotation