[英]what are the relationship between O(nlogn)+O(n), O(nlogn) and O(nlogn + n)?
Intuitively, I thought the three expressions are equivalent. 凭直觉,我认为这三个表达式是等效的。
For example, if an algorithm runs in O(nlogn) + O(n)
or O(nlogn + n)
(I'm confused), can I say that's an O(nlogn)
algorithm? 例如,如果某个算法以
O(nlogn) + O(n)
或O(nlogn + n)
(我很困惑)运行,那么我可以说这是O(nlogn)
算法吗?
what's the truth? 真相是什么
Yes, you can say that's an O(nlogn) . 是的,您可以说这是O(nlogn) 。
When you are trying to estimate complexity of your algorithm you start with all parts (choose the worst operation which is in each part and ignore the fast ones - hey it's just an estimate). 当您尝试估计算法的复杂性时,您将从所有部分入手(选择每个部分中最糟糕的操作,而忽略快速部分-嘿,这只是一个估计)。 First part is nlogn and the second part is n.
第一部分为nlogn,第二部分为n。
Beacause you don't want/can/need it to be accurate. 因为您不希望/不希望它是准确的。
O(nlogn + n) - or - O(nlogn) + O(n) -> nlogn grows faster then O(n) and therefore you can ignore O(n) -> O(nlogn) O(nlogn + n)-或-O(nlogn)+ O(n)-> nlogn的增长快于O(n),因此您可以忽略O(n)-> O(nlogn)
It's all about how fast is the function growing - think about it like it's huge n then you'll see why you can ignore the slower growing function. 这完全取决于函数的增长速度-仔细考虑它,然后您会明白为什么您可以忽略增长缓慢的函数。
For more exact explanation: http://en.wikipedia.org/wiki/Big_O_notation 有关更确切的说明,请访问: http : //en.wikipedia.org/wiki/Big_O_notation
O(nlogn)= O(nlogn) + O(n) =O(nlogn+n)
in fact if O(expression1) > O(expression2)
then you have: 实际上,如果
O(expression1) > O(expression2)
则您具有:
O(expression1)= O(expression1) + O(expression2) =O(expression1+expression2)
in this case expression1 = nlogn
and expression2 = n
在这种情况下,
expression1 = nlogn
和expression2 = n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.