词典顺序的定义? [英] Definition of a lexicographical order?

查看:130
本文介绍了词典顺序的定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在阅读 std :: next_permutation 函数,并且遇到了术语字典顺序".在特定的时间,我对这个词没有任何经验,谷歌搜索这个词,却只发现了这种类型的命令的某种含糊的定义,包括维基文章(至少对我来说是这样).

I am currently reading about the std::next_permutation function and encountered the term "lexicographical order". At the particular time, I had no experience with this term whatsoever so did a google search for this and found only somewhat cryptic definitions of this type of order, including the wiki article (at least they are to me).

那么有人可以尝试帮助我理解这一点吗?对您来说,这个术语的好"定义是什么?

So could anybody try to help me understand this? What is a "good" definition of this term to you?

关于维基文章-他们声称​​词典顺序也被称为字母顺序,但是当我继续阅读时,我了解到它们并不相同.因此,正在进行的比较使我有些困惑.

Regarding the wiki article - they claim that lexicographical order is also known as alphabetical order but as I continue reading, I get the understanding that they are not the same. Thus, the ongoing comparison confuses me a bit.

推荐答案

在正常的英语用法中,当我们按字母顺序对单词进行排序时,我们采用两个规则:

In normal English usage, when we sort words alphabetically, we employ two rules:

  • 如果两个单词的第一个字母相同,我们将比较第二个单词.如果第二个字母相同,我们比较第三个字母,等等.最后,如果第一个不同的字母位于相应字母之前,则一个单词位于另一个单词之前.

  • If two words have the same first letter, we compare the second. If the second letters are the same, we compare the third, etc. Finally, one word comes before the other if the first differing letter comes before the corresponding letter.

如果两个单词在短单词的长度之前都是相同的,则短单词排在前.

If two words are identical up to the length of the shorter word, the shorter word comes first.

因此,"Tom"在"Tooth"之前.第一个字母是相同的("T"),第二个字母是相同的"o",但是第三个字母diff和"m"在"o"之前.因此,汤姆"位于牙齿"之前.

So "Tom" comes before "Tooth". The first letters are identical ("T"), the second letters are identical "o", but the third letters diff and "m" comes before "o". Therefore "Tom" comes before "Tooth".

"Tom"在"Tomas"之前,因为两个单词在前三个字母"Tom"中是相同的,并且"Tom"比"Tomas"短.

"Tom" comes before "Tomas" because the two words are identical through the first three letters "Tom" and "Tom" is shorter than "Tomas".

词典顺序只是字母顺序,一般用于非字母值.考虑一个值序列,不一定是字母:

Lexicographic order is simply alphabetic ordering, generalized for non-letter values. Consider a sequence of values, not necessarily letters:

(1,5,10)在(1,6,3)之前,因为"5"在"6"之前.

(1,5,10) comes before (1,6,3) because "5" comes before "6".

(1,5,10)在(1,5,10,15,20)之前,因为(1,5,10)比(1,5,10,15,20)短.

(1,5,10) comes before (1,5,10,15,20) because (1,5,10) is shorter than (1,5,10,15,20).

如果序列的元素具有某些特定含义,则字典顺序特别有用,其中较早的值具有较高的优先级.例如,考虑以下时间:9:13 AM和8:25 AM.如果我们用序列(9,13)和(8,25)表示它们,那么(8,25)在(9,13)之前,因为8在9之前.例如,(9,13)在(9,45)之前,因为13在45之前.如您所见,按字典顺序,小时字段的优先级高于分钟字段.

Lexicographic ordering is particularly useful if the elements of the sequence have some specific meaning, with the earlier values giving a higher precedence. For example, consider these times: 9:13 AM and 8:25 AM. If we represent these with the sequence (9,13) and (8,25), then (8,25) comes before (9,13) because 8 comes before 9. What if the hours are the same? For example, (9,13) comes before (9,45) because 13 comes before 45. As you can see, lexicographic ordering allows the hour field to have a higher precedence than the minute field.

这篇关于词典顺序的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆