Home computickets What is lexicographic comparison and what is it?

What is lexicographic comparison and what is it?

Author

Date

Category

I met in the book the term lexicographic comparison I would like to understand what it is.


Answer 1, authority 100%

This comparison is “like in a dictionary” or “like in a phone book” – alphabetically. If the first letters match, the second is compared, if the second match, the third, and so on.


Answer 2, authority 100%

From Wikipedia:

Lexicographic order is a linear ordering relation on a set of words of length n over some ordered alphabet . The lexicographic order got its name by analogy with sorting alphabetically in a dictionary.

The word a precedes the word b (a & lt; b ) if the first m characters of the words match, and m + 1 the character of the word a is less (relative to the ordering relation specified in ) m + 1 the character of the word b .

If the first m characters of the words match, after which the word a ends, then it is also considered to precede b (i.e., the missing character less than any character).

Thus, the following equalities and inequalities hold for strings with respect to lexicographic order:

"abc" == "abc" // true
"123" == "123" // true
"123" & lt; "124" // true
"0999999" & lt; "123" // true
"123" & lt; "3" // true
"12" & lt; "123" // true
"123" & lt; "1234" // true

Learn more about lexicographic order .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions