algorithm - Big-Oh类之间的数学关系

标签 algorithm big-o complexity-theory

我的课本是这样描述关系的:

There is a very nice mathematical intuition which describes these classes too. Suppose we have an algorithm which has running time N0 when given an input of size n, and a running time of N1 on an input of size 2n. We can characterize the rates of growth in terms of the relationship between N0 and N1:

Big-Oh      Relationship

O(log n)    N1 ≈ N0 + c
O(n)        N1 ≈ 2N0
O(n²)       N1 ≈ 4N0
O(2ⁿ)       N1 ≈ (N0)²

这是为什么?

最佳答案

那是因为如果 f(n)O(g(n)) 中那么它可以被认为像 k * g( n) 对于一些 k

例如,如果 f(n) = O(log(n)) 那么它的行为类似于 k log(n),现在 f( 2n) ≈ k log(2n) = k (log(2) + log(n)) = k log(2) + k log(n) ≈ k log(2) + f(n) 并且c = k log(2) 是您想要的方程式。

请注意,这只是的粗略直觉。它失效的一个例子是 f(n) = (2 + sin(n)) log(n) = O(log(n))。振荡的 2 + sin(n) 位意味着 f(2n)-f(n) 基本上可以是任何东西。

我个人认为这种粗略的直觉具有误导性,因此比无用更糟糕。其他人发现它非常有帮助。自己决定给它多少重量。

关于algorithm - Big-Oh类之间的数学关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52730657/

相关文章:

使用 node.js 进行缓冲音频播放的算法/技术

java - 这个算法是免费的吗?

c# - 函数的复杂性和算法

big-o - O(n) 算法的计算时间可以超过 O(n^2) 吗?

算法的算法分析(big-O)

c++ - Introsort (quicksort + heapsort) 实现和复杂度

sql - 在 SQL (T-SQL) 中做高级逻辑 - 匹配算法

java - 组合java的组合

c++ - 大小的时间复杂度是多少?

java - 确定算法的时间复杂度