O(N + NM)可以简化为O(NM)吗?

编程入门 行业动态 更新时间:2024-10-23 15:20:34
本文介绍了O(N + NM)可以简化为O(NM)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设N和M是算法的两个参数.以下简化是否正确?

O(N+NM) = O[N(1+M)] = O(NM)

换句话说,是否可以在这种情况下删除常量?

解决方案

TL; DR 是

说明

根据Big-Oh表示法的定义,对于所有足够大的变量值,如果O(.)内部的项证明是小于常数乘以另一个项的常数,则可以删除较小的项.

>

您可以在此处找到更精确的定义.但是一些示例后果是:

  • O(1000 * N + N ^ 2)= O(N ^ 2),因为N ^ 2会在N> 1000时使1000 * N变小

  • O(N + M)无法简化

  • 因为N + NM <O,所以n = O(N + NM)= O(NM). N> 1和M> 1

    分别为2(NM)

Suppose that N and M are two parameters of an algorithm. Is the following simplification correct?

O(N+NM) = O[N(1+M)] = O(NM)

In other words, is it allowed to remove the constant in such a context?

解决方案

TL;DR Yes

Explanation

By the definition of the Big-Oh notation, if a term inside the O(.) is provably smaller than a constant times another term for all sufficiently large values of the variable, then you can drop the smaller term.

You can find a more precise definition of Big-Oh here, but some example consequences are that:

  • O(1000*N+N^2) = O(N^2) since N^2 will dwarf 1000*N as soon as N>1000

  • O(N+M) cannot be simplified

  • O(N+NM) = O(NM) since N+NM < 2(NM) as soon as N>1 and M>1

更多推荐

O(N + NM)可以简化为O(NM)吗?

本文发布于:2023-11-29 17:27:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647088.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!