Lexicographic ordering is similar to dictionary ordering, but it extends the idea to object other than letters. It allows us to place sequences of items, drawn from a particular set, in a well defined order.
For example, a word is a sequence of items from the set of letters (a to z). Alphabetic ordering considers each word, letter by letter. So if we compare the words "cat" and "cart":
Therefore, of course, "cart" comes before "cat" is alphabetical (therefore lexicographical) order.
A number is a sequence of items from the set of digits (0 to 9). Consider the two numbers 206 and 2035.
If we arrange those values in increasing numerical order, the clearly 206 comes before 2035.
In lexicographical ordering, we consider each digit in turn:
Therefore 2035 comes before 206 in lexicographical order, even though it is numerically larger.
Suppose we had a collection of counters with colours red, orange, yellow, green, blue, indigo and violet - the rainbow colours:
We can apply lexicographical ordering, provided we define the order of the items in the set. Unlike letters and digits, colours don't have a natural order. But we can specify that we are going to use the rainbow order defined above.
As an example, consider the three colour sequence OGB, and the four colours sequence OGYR.
The first 2 colours are the same in both sequences, but when we compare the third colour, yellow is before blue, therefore OGYR comes before OGB.
Copyright (c) Axlesoft Ltd 2021