大O符号

✍ dations ◷ 2025-10-01 09:23:13 #算法分析,数学表示法,数学符号,渐近分析

大O符号(英语:Big O notation),又称为渐进符号,是用于描述函数渐近行为的数学符号。更确切地说,它是用另一个(通常更简单的)函数来描述一个函数数量级的渐近上界。在数学中,它一般用来刻画被截断的无穷级数尤其是渐近级数的剩余项;在计算机科学中,它在分析算法复杂性的方面非常有用。

大O符号是由德国数论学家保罗·巴赫曼(英语:Paul Bachmann)在其1892年的著作《解析数论》()首先引入的。而这个记号则是在另一位德国数论学家艾德蒙·朗道(英语:Edmund Landau)的著作中才推广的,因此它有时又称为朗道符号(Landau symbols)。代表“order of ...”(……阶)的大O,最初是一个大写希腊字母“Ο”(omicron),现今用的是大写拉丁字母“O”。

大O符号在分析算法效率的时候非常有用。举个例子,解决一个规模为 n {\displaystyle n} 的问题所花费的时间(或者所需步骤的数目)可以表示为: T ( n ) = 4 n 2 2 n + 2 {\displaystyle T(n)=4n^{2}-2n+2} 。当 n {\displaystyle n} 增大时, n 2 {\displaystyle n^{2}} 项将开始占主导地位,而其他各项可以被忽略。举例说明:当 n = 500 {\displaystyle n=500} 4 n 2 {\displaystyle 4n^{2}} 项是 2 n {\displaystyle 2n} 项的1000倍大,因此在大多数场合下,省略后者对表达式的值的影响将是可以忽略不计的。

进一步看,如果我们与任一其他级的表达式比较, n 2 {\displaystyle n^{2}} 项的系数也是无关紧要的。例如:一个包含 n 3 {\displaystyle n^{3}} n 2 {\displaystyle n^{2}} 项的表达式,即使 T ( n ) = 1 , 000 , 000 n 2 {\displaystyle T(n)=1,000,000\cdot n^{2}} ,假定 U ( n ) = n 3 {\displaystyle U(n)=n^{3}} ,一旦 n {\displaystyle n} 增长到大于1,000,000,后者就会一直超越前者( T ( 1 , 000 , 000 ) = 1 , 000 , 000 3 = U ( 1 , 000 , 000 ) {\displaystyle T(1,000,000)=1,000,000^{3}=U(1,000,000)} )。


这样,针对第一个例子 T ( n ) = 4 n 2 2 n + 2 {\displaystyle T(n)=4n^{2}-2n+2} , 大O符号就记下剩余的部分,写作:

并且我们就说该算法具有 n 2 {\displaystyle n^{2}} 阶(平方阶)的时间复杂度。

大O也可以用来描述数学函数估计中的误差项。例如 e x {\displaystyle e^{x}} 的泰勒展开:

这表示,如果 x {\displaystyle x} 足够接近于0,那么误差 e x ( 1 + x + x 2 2 ) {\displaystyle e^{x}-\left(1+x+{\frac {x^{2}}{2}}\right)} 的绝对值小于 x 3 {\displaystyle x^{3}} 的某一常数倍。

注:泰勒展开的误差余项 r 3 ( x ) {\displaystyle r_{3}(x)} 是关于 x 3 {\displaystyle x^{3}} 一个高阶无穷小量,用小o来表示,即: r 3 ( x ) {\displaystyle r_{3}(x)} = o ( x 3 ) {\displaystyle o(x^{3})} lim x 0 r 3 ( x ) x 3 = 0 {\displaystyle \textstyle \lim _{x\to 0}\displaystyle {\frac {r_{3}(x)}{x^{3}}}=0}

给定两个定义在实数某子集上的关于 x {\displaystyle x} 的函数 f ( x ) {\displaystyle f(x)} g ( x ) {\displaystyle g(x)} ,当 x {\displaystyle x} 趋近于无穷大时,当且仅当存在正常量 M {\displaystyle M} ,使得对于所有足够大(sufficiently_large)的 x {\displaystyle x} ,都有 f ( x ) {\displaystyle f(x)} 的绝对值小于等于 M {\displaystyle M} 乘以 g ( x ) {\displaystyle g(x)} 的绝对值,那么我们就可以说,当 x {\displaystyle x\to \infty } 时,

也就是说,假如当且仅当存在正实数 M {\displaystyle M} 和实数 x {\displaystyle x} 0,使得对于所有的 x x 0 {\displaystyle x\geq x_{0}} ,均有: | f ( x ) |   M | g ( x ) | {\displaystyle |f(x)|\leq \ M|g(x)|} 成立,我们就可以认为, f ( x ) = O ( g ( x ) ) {\displaystyle f(x)=\mathrm {O} (g(x))}

在很多情况下,我们会省略“当 x {\displaystyle x} 趋近于无限大时”这个前提,而简写为:

此概念也可以用于描述函数 f {\displaystyle f} 在接近实数 a {\displaystyle a} 时的行为,通常 a = 0 {\displaystyle a=0} 。当我们说,当 x a {\displaystyle x\to a} 时,有 f ( x ) = O ( g ( x ) ) {\displaystyle f(x)=\mathrm {O} (g(x))} ,也就相当于称,当且仅当存在正实数 M {\displaystyle M} 和实数 δ {\displaystyle \delta } ,使得对于所有的 0 | x a | δ {\displaystyle 0\leq |x-a|\leq \delta } ,均有 | f ( x ) |   M | g ( x ) | {\displaystyle |f(x)|\leq \ M|g(x)|} 成立。

如果当 x {\displaystyle x} a {\displaystyle a} 足够接近(sufficiently_close)时, g ( x ) {\displaystyle g(x)} 的值仍不为0,这两种定义就可以统一用上极限来表示:

在具体的运用中,我们不一定使用大O符号的标准定义,而是使用几条简化规则来求出关于函数 f {\displaystyle f} 的大O表示:

比如,使 f ( x ) = 6 x 4 2 x 3 + 5 {\displaystyle f(x)=6x^{4}-2x^{3}+5} ,我们想要用大O符号来简化这个函数,来描述 x {\displaystyle x} 接近无穷大时函数的增长情况。此函数由三项相加而成, 6 x 4 {\displaystyle 6x^{4}} 2 x 3 {\displaystyle -2x^{3}} 5 {\displaystyle 5} 。由于增长最快的是 6 x 4 {\displaystyle 6x^{4}} 这一项(因为阶最高,在x接近无穷大时,其对和的影响会大大超过其余两项),应用第一条规则,保留它而省略其他两项。对于 6 x 4 {\displaystyle 6x^{4}} ,由两项相乘而得, 6 {\displaystyle 6} x 4 {\displaystyle x^{4}} ;应用第二条规则, 6 {\displaystyle 6} 是无关x的常数,所以省略。最后结果为 x 4 {\displaystyle x^{4}} ,也即 g ( x ) = x 4 {\displaystyle g(x)=x^{4}} 。故有:

我们可以将上式扩展为标准定义形式:

可以(粗略)求出 M {\displaystyle M} x 0 {\displaystyle x_{0}} 的值来验证。使 x 0 = 1 {\displaystyle x_{0}=1}

M {\displaystyle M} 可以为13。故两者都存在。

下面是在分析算法的时候常见的函数分类列表。所有这些函数都处于 n {\displaystyle n} 趋近于无穷大的情况下,增长得慢的函数列在上面。 c {\displaystyle c} 是一个任意常数。

大O是最经常使用的比较函数的渐近符号。

大O符号经常被误用:有的作者可能会使用大O符号表达大Θ符号的含义。因此在看到大O符号时应首先确定其是否为误用。

相关

  • 语族语言系属分类(英语:Language family)是指根据语言的演化关系,对语言进行分类的方法,具有相同祖先的语言被归为一类,类似生物分类法。分类依据为各语言语音、词汇、语法之间的对应
  • 赫里亚垃圾场坐标:32°1′36.93″N 34°49′26.71″E / 32.0269250°N 34.8240861°E / 32.0269250; 34.8240861阿里尔·沙龙公园(פארק אריאל שרון - Ariel Sharon Park / פ
  • 萨克马尔期萨克马尔期(英语:Sakmarian)是二叠纪的第二个时期,年代大约位于293.52–290.1百万年前。
  • 浊点萃取浊点萃取(Cloud point extraction)是一种新型的液-液萃取技术,成本低,易分离且操作非常简单,在金属离子的分离富集中应用日趋广泛。当表面活性剂水溶液加热超过一定温度时,溶液会
  • 杜审进杜审进(910年-988年),北宋定州安喜县(今河北省定州市)人。宋太祖、宋太宗的舅舅,杜审琦、昭宪太后之弟。建隆三年(962年),授右神武大将军,复改右羽林大将军。乾德元年(963年)领贺州刺史。
  • 西野胜海西野胜海(日语:西野かつみ)是日本轻小说作家、漫画原作者。男性。岩手县出身。现在居住于岩手县盛冈市。
  • SGO48SGO48为以越南胡志明市为活动据点的女子偶像团体,同时也是日本偶像团体AKB48的第7个海外姐妹团。总制作人由作词家秋元康担任。团体名称中“SGO”以所在地胡志明市旧名西贡的
  • 皮乌斯·恩佐皮乌斯·恩佐(Pius Njawé,1957年3月4日-2010年7月12日)是一个喀麦隆记者和报社《信使》(Le Messager)的董事。生前因报导禁止内容而遭逮捕逾100次。因此,恩佐亦获得了数个新闻自由
  • 增田大辉增田大辉(日语:ますだ だいき、1993年7月29日- ),是日本的棒球运动员之一,曾效力于四国岛联盟德岛蓝短袜队,2015年透过育成选秀以育成选手的身份被读卖巨人队指名,2017年升格成支配
  • 桥本岳桥本岳(日语:橋本岳, 1974年2月5日-),日本政治人物,众议院议员,隶属于自由民主党。现任厚生劳动省副大臣。父亲是曾任日本内阁总理大臣的桥本龙太郎。1974年出生于冈山县总社市,1996