简体   繁体   English

O(nlogn)+ O(n)的时间复杂度就是O(nlogn)吗?

[英]Is a time complexity of O(nlogn) + O(n) just O(nlogn)?

Let's say I have an array of length n and I sorted through it using a sorting algorithm with time nlogn . 假设我有一个长度为n的数组,并且使用时间为nlogn的排序算法对其进行了排序。 After getting this sorted array, I iterate through it to find any repeating elements with linear time. 获得此排序数组后,我将对其进行遍历以找到具有线性时间的任何重复元素。 My understanding is that since the operations happened separately, this would be time O(nlogn) + O(n) and not O(nlogn+n) . 我的理解是,由于操作是分开进行的,所以这将是时间O(nlogn) + O(n)而不是O(nlogn+n) If that's the case, would nlogn over take the linear time complexity making the final time complexity O(nlogn) ? 如果是这样, nlogn是否会采用线性时间复杂度,从而使最终时间复杂度为O(nlogn)

是的,因为对于大n,log(n)> 1,所以O(nlog(n))是O(n)的超集

O(nlogn) + O(n) and not O(nlogn+n) O(nlogn)+ O(n)而不是O(nlogn + n)

There is no such thing; 哪有这回事; O ( n log n ) + O ( n ) and O ( n log n + n ) are equal, and both are equal to O ( n log n ). On log n )+ On )和On log n + n )相等,并且都等于On log n )。 So it's not possible for a function to be in one and not the other. 因此,一个函数不可能存在于一个函数中,而不能存在于另一个函数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM