Lexicographical order
Encyclopedia : L : LE : LEX : Lexicographical order
In mathematics, the lexicographical order, (a.k.a. dictionary order or alphabetic order), is a natural order structure of the cartesian product of two ordered sets. Given A and B, two ordered sets, the lexicographical order in the cartesian product A × B is defined as
- (a,b) ≤ (a′,b′) if and only if a < a′, or a = a′ and b ≤ b′.
- a1a2 ... ak
- b1b2 ... bk
For the purpose of dictionaries, etc., one may assume that all words have the same length, by adding blank spaces at the end, and considering the blank space as a special character which comes before any other letter in the alphabet. This also allows ordering of phrases. See alphabetical order.
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'.
Case of multiple products
Suppose
- [ \]
- [ \]
- [\ \ <^d ]
- [ A_1 \times A_2 \times \cdots \times A_n]
- [ (a_1, a_2, \dots, a_n) <^d (b_1,b_2, \dots, b_n) \iff (\exists\ m > 0) \ (\forall\ i < m) (a_i = b_i) \land (a_m <_m b_m)]
- [ \ \ a_m <_m b_m]
Informally,
- [ \ \ a_1]
- [ \ \ a_2 ]
This could be more elegantly defined recursively by defining the ordering of any set
- [ \ \ C= A_j \times A_ \times \cdots \times A_k ]
- [ \ \ <^d (C)]
- [ a <^d (A_i) a' \iff (a <_i a')]
- [ (a,b) <^d (A_i \times B) (a',b') \iff a <^d (A) a' \lor ( a=a' \ \land \ b <^d (B) b')]
Or, more simply put, compare the first terms if they are equal compare the second — and so on.
Monomials
In algebra it is traditional to order terms in a polynomial, by ordering the monomials in the indeterminates. This is fundamental, in order 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 > ...
- ... > X3 > X2 > X
- X > Yk for all k.
C/C++ function for case insensitive string comparison
//if the two strings were found equal inside "for" decide the precedence
//by checking their size
if(str_1.size()
bool lexComp(std::string str_1, std::string str_2 )
See also
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
