时间复杂度

发布于 2024-10-07 04:04:52 字数 219 浏览 0 评论 0 原文

你好 我有一个问题:

考虑我有 T(n) = m * n^2 (n T(n) = O(m) 这样写是否正确?因为我写了 T(n) = m*n*n 所以因为 n 我们有 T(n) = O(m) > 谢谢

Hi
I have a question that:

consider I have T(n) = m * n^2 (n<m)
is this correct to write T(n) = O(m) ? because I have written T(n) = m*n*n So because n<m we have T(n) = O(m)
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹短裙飘 2024-10-14 04:04:52

不,你能做的最好的事情就是编写T(n,m) = O(m^3)。 <代码>n < m 是一个非常弱的条件,基本上只是在 O(m) 中给出n。例如,n 始终可以是m-1

编辑:我的第一个答案不精确,因为 T 只是 n 中的函数。如果 m 是常数,答案仍然成立,但 O(m^3) 等于 O(1)。

No, the best thing you can do is to write T(n,m) = O(m^3). n < m is a very weak condition and basically just gives you n in O(m). For example, n could always be m-1.

Edit: My first answer was imprecise, as T was only a function in n. If m is constant, the answer is still holds, but O(m^3) is equal to O(1).

不再让梦枯萎 2024-10-14 04:04:52

我相信在这种情况下 T(n) = O(n^2)

正式定义大O的:

f(x) = O(g(x)) 当且仅当存在正实数 M 和实数 x0 使得 |f(x)| ≤ M|g(x)|对于所有 x > x0。

在您的情况下,T(n) 将始终小于或等于 m(n^2)。

I believe in this case T(n) = O(n^2)

The formal definition of big-O:

f(x) = O(g(x)) if and only if there exists a positive real number M and a real number x0 such that |f(x)| ≤ M|g(x)| for all x > x0.

In your case, T(n) will always be less than or equal to m(n^2).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文