Javatpoint Logo
Javatpoint Logo

Lexicographic Orders

The lexicographic order can be described as an order of the Cartesian product of a minimum two partially ordered sets, X and Y. We can also call the lexicographic order as dictionary order, alphabetic order, and lexicographical order. The lexicographic order is indicated by the symbol <. There are many categories in which we can use the lexicographic order, which is described as follows:

Order involving Two sets

Suppose there are two partially ordered sets (X, <1) and (Y, <2). We will use the following way to show the lexicographic order < on Cartesian product X * Y:

(x, y) < (z, d)

If and only if

x <1 z or (x = z and y <2 d).

Order Involving N sets

We can also generalize the above-defined Cartesian product into the n posets. For this, we will assume the partially ordered set (X1, <1), (X2, <2), (X3, <3), …., (Xn, <n). We will use the following way to show the lexicographic order < on Cartesian product X1, X2, X3, ……, Xn:

(x1, x2, x3, …., xn) < (y1, y2, y3, …., yn),

Or it can have an integer 0 < i ≤ in such a way that

x1 = y1, x2 = y2, x3 = y3,….., xn-1 = yn-1 and ai < bi.

From the above explanation, we can say that if X1, X2, X3, ….., Xn are the partially ordered set, in this case, the lexicographic order will also be in partial order. Similarly, if there is a proper arrangement (well-ordered) of all these sets, in this case, the lexicographic order will be in total order.

Ordering of Words

Suppose there is a certain alphabet that is indicated by set X. The letter x1, x2, x3, …., xk of the alphabet X must assume to be strictly totally ordered like this:

x1 < x2 < x3 < …. < xk.

The strings of length n or words will be indicated by the elements of nth Cartesian power Xn. On the basis of the order of symbols, we can determine the order of two words. For this, we will check the first place where two words differ, and we will start checking from the beginning of the words.

If there are two words that contain two different lengths, then we will pad the shortest word with the trailing blank characters so that the shortest word can contain the same length as the longest word. If there is any blank symbol, then it must come first before any other symbol in the alphabet. In this way, we can compare the words lexicographically.

So with the help of basic Latin alphabet, the name of the city can be sorted in a way that is described as follows:

Cairo < Delhi < Jakarta < Kinshasa < Lagos < London < Los Angeles < Mexico < Moscow < Mumbai < New York < Paris < Shanghai < Tokyo

In order to compare the words of different lengths, we also have one more convention, which is very useful and frequently used for the comparison, and this convention is known as the shortlex order. In the process of shortlex word order, the shortest word will always come before a longer word. On the basis of shortlex ordering, the above-described city will be arranged in the following order:

Cairo < Delhi < Lagos < Paris < Tokyo < London < Mexico < Moscow < Mumbai < Jakarta < Kinshasa < New York < Shanghai < Los Angeles

Ordering of Numeric Tuples

Suppose there is A = N. Where, set Nn is used to indicate the n tuples of natural numbers. For example: (2, 5, 8, 9) for n = 4, or (1, 4, 10, 15, 18, 20) for n = 6.

The lexicographic order is used to compare the n tuples of natural numbers. If we use it to apply the less than order < on the set of natural numbers N, then we can define it in the following way:

(x1, x2, x3, …, xn) < (y1, y2, y3, …., yn),

Here i ≤ n in such a way that aj = bj for all j < i and ai ≤ bi.

For example:

(1, 1) < (1, 2) < (1, 3, 2) < (1, 3, 5); (7, 5, 4, 2) < (7, 6, 4, 2).

In the same way, we can use the set of other numerical objects and define the lexicographic orders on them. We can define it on Rn, which is used to contain the n tuples of real numbers, or Zn, which is used to contain n tuples of integers.

Ordering of Subsets

If there are some objects which are indicated in the form of a list with a partial ordering, in this case, we can use the lexicographic order so that we can sort any object. Here we have to order the subsets of set X that have n number of elements. These can be called the subset of size k or all subsets of the power set of X.

We should remember that the order of elements within the subsets will not matter in case of defining the ordering of subsets. Therefore, on the basis of the implied or given ordering rules first, we will arrange them in increasing order. So with the help of standard less than order, we can arrange the numbers, and with the help of alphabetic order, we can sort the letter. After that, we are able to apply the lexicographic ordering to subsets.

For example: In this example, we have a subset of X = {x, y, z, d}, and we will show it in lexicographic orders in the following way:

Φ < {x} < {x, y} < {x, y, z} < {x, y, z, d} < {x, y, d} < {x, z} < {x, z, d} < {x, d} < {y} < {y, z} < {y, z, d} < {y, d} < {z} < {z, d} < {d}

Lexicographic order in Normal language

A lexicographic order can be described as an arrangement of words, characters, or numbers in alphabetic order. The letters of this order must be sorted from A to Z. The lexicographic order can also be called the dictionary order. This is because the search for lexicographic order and the search for a particular word in an actual dictionary is similar to each other. For this, we will begin our search from the section that has those types of words that begin with the first letter of desired word. After this, we will start from that section, and start our search for those words that have the second letter of the desired word, and the process will go on.

Now we will understand the lexicographic order with the help of an example, which is described as follows:

Lexicographic Orders

In the start of this example, we have a list of prime numbers, i.e., {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}. When we arrange these prime numbers with the help of lexicographic order, then the list will become: {11, 13, 17, 19, 2, 23, 29, 3, 5, 7}.

Now we will discuss one more example so that we can more understand the lexicographic order.

Lexicographic Orders

In the above example, there is a list of two words, i.e., {educative, educated}. Now we will sort this two-word list with the help of lexicographic order. For this, we will compare these two words letter by letter, and then we will sort these letters in the alphabetic order. After this, we will get our result in the form of a list like this {educated, educative}.

Examples of Lexicographic order

The lexicographic order contains a lot of examples, and some of them are described as follows:

Example 1: In this example, we have to use the lexicographic order, which has less than a relation, and we have to define the Cartesian square A2 with the help of this order, where A = {1, 2, 3, 4}. Here we have to determine all pairs of A2 which are greater than (3, 2).

Solution: The lexicographic order on A2 will be represented as follows:

(1, 1) < (1, 2) < (1, 3) < (1, 4) < (2, 1) < (2, 2) < (2, 3) < (2, 4) < (3, 1) < (3, 2) < (3, 3) < (3, 4) < (4, 1) < (4, 2) < (4, 3) < (4, 4).

Now from the above pairs, we will select that pairs that are greater than (3, 2), which are described as follows:

(3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)

Example 2: In this example, we have to use the lexicographic order, which has less than a relation, and we have to define the Cartesian square B3 with the help of this order, where B = {1, 2, 3}. Here we have to determine all elements in B3 which are greater than (2, 1, 3) and less than (3, 2, 1).

Solution: The lexicographic order on the list of elements of B3 will be represented as follows:

(1, 1, 1) < (1, 1, 2) < (1, 1, 3) < (1, 2, 1) < …. < (3, 2, 3) < (3, 3, 1) < (3, 3, 2) < (3, 3, 3)

Now from the above pairs, we will select that pairs that are greater than (2, 1, 3) and less than (3, 2, 1), which are described as follows:

(2, 2, 1), (2, 2, 2), (2, 2, 3), (2, 3, 1), (2, 3, 2), (2, 3, 3), (3, 1, 1), (3, 1, 2), (3, 1, 3)

Example 3: In this example, we have a list of all 3 subsets of set {x, y, z, u, v}, and we have to arrange them in the lexicographic order.

Solution: The lexicographic order on the list of all 3 subsets of set {x, y, z, u, v} will be represented as follows:

{x, y, z} < {x, y, u} < {x, y, v} < {x, z, u} < {x, z, v} < {x, u, v} < {y, z, u} < {y, z, v} < {y, u, v} < {z, u, v}.

Example 4: In this example, we have a list of all 4 subsets of set {1, 2, 3, 4, 5, 6}, and we have to arrange them in the lexicographic order.

Solution: The lexicographic order on the list of all 4 subsets of set {1, 2, 3, 4, 5, 6} will be represented as follows:

{1, 2, 3, 4} < {1, 2, 3, 5} < {1, 2, 3, 6} < {1, 3, 4, 5} < {1, 3, 4, 6} < {1, 4, 5, 6} < {2, 3, 4, 5} < {2, 3, 4, 6} < {2, 4, 5, 6} < {3, 4, 5, 6}.

Example 5: In this example, there are two posets (A, ) and , where A = {1, 2, 3} and P(A) are used to indicate the power set of A. Here we have a lexicographic order with less than relation (<), which is defined on the Cartesian product A * P(A). Now we have to find out whether the following statements are true or false.

  1. (2, φ) < (1, {1, 2, 3})
  2. (1, {1}) < (2, {2, 3})
  3. (2, {1}) < (2, {2, 3})
  4. (3, {1, 3}) < (3, {2, 3})
  5. (3, {1, 3}) < (3, {1, 2, 3})

Solution:

  1. The first statement (2, φ) < (1, {1, 2, 3}) contains the condition 2 That's why this statement is false.
  2. The second statement (1, {1}) < (2, {2, 3}) contains the condition 1 ≤ That's why this statement is true.
  3. The third statement (2, {1}) < (2, {2, 3}) contains the condition {1} {2, 3}. That's why this statement is false.
  4. Same as, the fourth statement (3, {1, 3}) < (3, {2, 3}) contains the condition {1, 3} {2, 3}. That's why this statement is false.
  5. The last statement (3, {1, 3}) < (3, {1, 2, 3}) contains the condition 3 = 3 and {1, 3} {1, 2, 3}. That's why this statement is true.

Example 6: In this example, there are two posets (B, |) and where B = {2, 3, 4, 8}, "|". Here | is used to indicate the divisibility relation, and P(A) is used to indicate the power set of B. Here we have a lexicographic order with less than relation (<), which is defined on the Cartesian product B * P(B). Now we have to find out whether the following statements are true or false.

  1. (2, φ) < (3, {4, 8})
  2. (2, {4}) < (4, {3, 8})
  3. (2, {4}) < (2, {3, 4, 8})
  4. (4, {2, 3}) < (4, {3, 4})
  5. (8, {1, 3}) < (4, {1, 2, 3})

Solution:

  1. The first statement (2, φ) < (3, {4, 8}) contains the condition 2 does not divide 3. That's why this statement is false.
  2. The second statement (2, {4}) < (4, {3, 8}) contains the condition 2 divides 4 (although {4} {3, 8}). That's why this statement is true.
  3. The third statement (2, {4}) < (2, {3, 4, 8}) contains the condition 2 = 2 and {4} {3, 4, 8}. That's why this statement is true.
  4. The fourth statement (4, {2, 3}) < (4, {3, 4}) contains the condition 4 = 4, but {2, 3} {3, 4}. That's why this statement is false.
  5. The last statement (8, {1, 3}) < (4, {1, 2, 3}) contains the condition 8 does not divide 4. That's why this statement is false.

Important Points

There are some important points related to lexicographic order, and some of them are described as follows:

  • We can readily extend the lexicographic order up to the Cartesian products of arbitrary length with the help of recursively applying this definition. We will do this with the help of observing that A * B * C = A* (B * C)
  • The lexicographic order will be increased in the numerical order or in the alphabetic order for the list of symbols if we apply it to permutations. For example: Suppose we have the permutations of {1, 2, 3}. The lexicographic orders of these permutations are 123, 132, 213, 231, 312, and 321.
  • When we apply the lexicographic order to the subsets, then on the basis of the smallest element, we can order the two subsets. For example: Suppose we have the subsets of {1, 2, 3}. The lexicographic orders of these subsets are {}, {1}, {1, 2}, {1, 2, 3}, {1, 3}, {2}, {2, 3}, {3}.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA