- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在根据代码摘录识别复杂性或最坏情况时,我了解什么是大 O 表示法。
在类里面,我被教导说,当谈到复杂性和大 O 表示法时,我们忽略低于 M
的小参数 n
和常数因子 C
。
这是在类里面给我的:
In Big-Oh notation. Let f be a function from N to the positive reals. (Think of f(n) as the running time for an argument of size n. It could be worst case or it could be average case.) Let g be another such function. We say that f ∈ O(g) when there is some natural number M and constant factor C, such that for all n > M, we have f(n) <= C × g(n). In logical symbols: ∃M. ∃C. ∀n > M. f(n) <= C × g(n)
我可以知道这句话是什么意思吗,特别是:
Let f be a function from N to the positive reals.
Let g be another such function.
We say that f ∈ O(g) when there is some natural number M and constant factor C, such that for all n > M, we have f(n) <= C × g(n). In logical symbols: ∃M. ∃C. ∀n > M. f(n) <= C × g(n)
最佳答案
总结:C 乘以 g 最终支配 f。
1 和 2。
Let f be a function from N to the positive reals. (Think of f(n) as the running time for an argument of size n. It could be worst case or it could be average case.) Let g be another such function.
OK:f 和 g 是从自然数 (N) 到正实数的函数。为什么来自自然数?我们假设参数的大小是我们可以精确指定的。自然数是我们可以精确指定的东西。实数不是。为什么是正实数?我们假设运行时间不一定是我们可以精确指定的。
但这里重要的实际上不是说了什么,而是没说了什么。没有人说 f 是单调递增的,或者 g 是多项式,或者其他什么。我们只知道 f 和 g 是函数。这几乎就是它的全部。是的,它们从自然数映射到正实数,但就限制而言,这是一个相当小的限制。所以这里的重点是:有很多很多函数 f 和 g 可供选择。唯一有点重要的限制是实数比自然数多得多。
3.
We say that f ∈ O(g) when there is some natural number M and constant factor C, such that for all n > M, we have f(n) <= C × g(n). In logical symbols: ∃M. ∃C. ∀n > M. f(n) <= C × g(n)
M 和 C 是常量。我们选择 M 和 C,我们就完成了。这里的重点是至少有一个 M和至少有一个C满足句子。不是:任何 M 也不是任何 C。声明是存在至少一个这样的M 和C。
另一方面,n 不是常数。我们可以选择 n 为任何数,只要它大于 M。声明说对于 any 选择 n(大于 M),至少可以找到 C 的一个值,所以如果你将 g(n) 乘以 C,这个乘积将大于 f(n)。 什么 n 并不重要,只要它大于 M。
当我们假设解除了其中一个限制时,我们考虑常数 M 和 C 的原因就变得很清楚了。假设语句没有提到 M:
We say that f ∈ O'(g) when there is some constant factor C, such that for all n, we have f(n) <= C × g(n). In logical symbols: ∃C. ∀n f(n) <= C × g(n)
现在说的是:考虑 f 的所有可能输出和 g 的所有可能输出的空间。如果我们将 g 的输出空间“扩张”一个常量 C,则它们中的每一个都将大于 f 中的任何一个点。现在这是比我们指定 M 时更强的陈述。如果 f(0) = 10 且 g(0) = 0 会怎样?现在,可以没有 C 使Cg(0) > Cf(0)
。因此,M“切断”了这些坏边。
这个页面有很好的解释和视觉效果,还有:https://xlinux.nist.gov/dads/HTML/bigOnotation.html
关于algorithm - Big O Notation - 自然数 M 和常数因子 C 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54831827/
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Big Theta Notation - what exactly does big Theta represent
我有一个作业要证明这些是对还是错: a) 150n^3 + 43n^2 + 50^n + 3 = Ω(n^5) b) n^10 + 30n^8 + 80n^6 = O(n^12) c) 55n + 3
我可以在 big.Int 上使用像 Text() 这样的方法,它工作正常,但是如果我返回一个 big.Int 然后使用“myfunc().Text()”会抛出一个错误,而如果我返回一个 * big.I
我正在用 PHP 开发一个网络应用程序,此时核心库的大小为 94kb。虽然我认为我现在是安全的,但多大才算太大?脚本的大小是否会成为一个问题,如果是这样,可以通过将脚本拆分为多个库来改善这一点吗? 我
我正在复习 Big-Oh 符号,但我在理解这个问题的解决方案时遇到了问题: Is 2n + 10 ≡ O(n)? Can we find c and n0? 2n + 10 = 10 n >= 10/
我最近陷入了争论/辩论中,我试图对正确的解决方案做出明确的判断。 众所周知, n! grows very quickly ,但究竟有多快,足以“隐藏”可能添加到其中的所有其他常量? 让我们假设我有这个
我很难找出这段代码的 Big-O 符号。 我需要找到两个 for 循环的符号。 public static int fragment(int n) { int sum = 0; for (in
给定两个函数: f(n)=O(log2n) 和 g(n)=O(log10n) 其中一个是否支配另一个? 最佳答案 请记住,任何碱基的对数都可以转换为仅以常数变化的公共(public)碱基。 因此它们都
经过修改,我们得出结论,时间复杂度实际上是O(2^n) 问题是时间复杂度是多少?是 O(2^n) 还是? 我相信这是因为 for 循环被认为运行了 n 次。然后嵌套的 while 循环运行 2^n 次
以下嵌套循环的 Big-O 时间复杂度是多少: for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) {
我很想知道经验丰富的 C 程序员认为可以按值传递的参数大小的上限是什么。 上下文:我有机会使用 2×2 矩阵,它位于一个结构体中: typedef struct { double a, b, c,
我很想知道经验丰富的 C 程序员认为可以按值传递的参数大小的上限是什么。 上下文:我有机会使用 2×2 矩阵,它位于一个结构体中: typedef struct { double a, b, c,
假设我们有一个问题,我们使用 X 算法实现了 O(n) 或 O(log n) 或 etc...。 n 的值何时大到我们必须考虑替代实现?让我们看看我是否可以更好地解释自己。 For n=10,000
这属于哪种 Big-O 表示法?我知道 setSearch() 和 removeAt() 是 O(n) 的顺序(假设它们是任意一种)。我知道如果没有 for 循环它肯定是 O(n),但是我很困惑如何计
这是我的问题,我已经设法为 a 部分提出了一个答案,但对于 b 部分,我对 b 部分的答案并不是很自信。 在最近的一起法庭案件中,一名法官以蔑视城市为由,下令第一天罚款 2 美元。 之后的每一天,直到
我正在尝试计算以下算法的大 O,但我很困惑,需要一些帮助: Algorithm 1. DFS(G,n) Input: G- the graph n- the current node 1
我们有一个使用 F5 BIG-IP 服务器进行负载平衡的潜在客户端。在确定我们是否可以将我们的产品与他们的负载均衡器干净地集成时,我开始查看 F5 提供的 API。问题是,如果没有 F5 服务器,我无
我正在尝试使用 react-big-calendar 包。 http://intljusticemission.github.io/react-big-calendar/examples/index.
我的任务是尝试找到给定 Java 方法的 big-O 和 big-Omega,但不知道如何找到。我知道 big-O 给出了上限,big-Omega 给出了下限,但是在查看程序(更不用说递归程序)时,我
我正在尝试确定以下陈述是对还是错。 如果 f(n) ∈ O(n) 且 g(n) ∈ Ω(n),则 f(n) + g(n) ∈ Θ(n)。 我想我理解添加相同的渐近 big-O。 O(n) + O(n)
我是一名优秀的程序员,十分优秀!