简体   繁体   English

复杂度logn和log之间的差异(sqrt(n))

[英]Difference between complexity logn and log(sqrt(n))

considering 考虑

log(sqrt(n)) = (1/2)log(n) log(sqrt(n))=(1/2)log(n)

And if for asymptotic analysis we don't consider the constant terms so, is O(log(sqrt(n))) is as good as O(log(n))? 如果对于渐近分析我们不考虑常数项,那么O(log(sqrt(n)))是否与O(log(n))一样好?

As per my understanding log(sqrt(n)) will grow slowly in comparison to log(n) if we increase the size of n. 据我所知,如果我们增加n的大小,log(sqrt(n))将与log(n)相比缓慢增长。 But I am not able understand the glitch in moving power of (1/2) at front? 但我无法理解前方(1/2)移动力的故障? Is it just this that factor 1/2 only slows down the rate? 只是因为1/2因素只会降低速度吗?

consider the case when we have log(n*n) represented as 2log(n) , and log(n)? 考虑我们将log(n * n)表示为2log(n)和log(n)的情况?

它渐近是一样的:

O(log(sqrt(n))) = O(log(n^1/2)) = O(1/2 log(n)) = O(log(n))

你是对的,O(log(sqrt(n)))与你的问题中给出的推理与O(log(n))相同。

Time(A) = log n

Time(B) = log sqrt(n) = log n^(1/2) = 1/2 log n

Asymptotically the same 渐近相同

O(Time(A)) = O(log n)

O(Time(B)) = O(1/2 log n) = O(log n)

O(Time(A)) = O(Time(B))

Insignificantly different 微不足道

Time(A) = 1   * log n

Time(B) = 1/2 * log n

Time(A) > Time(B)

Time(A) = 2 * Time(B)

Conclusion 结论

log n = 2 log sqrt(n)

Although the difference between log n and log sqrt(n) is in insignificant, log n will always take double the amount of time log sqrt(n) takes 虽然log nlog sqrt(n)之间的差异无关紧要,但log n总是需要log sqrt(n)占用的时间量的两倍

Visual 视觉

在此输入图像描述

The big-O notation ignores any constant multiplier. big-O表示法忽略任何常数乘数。

O(500000.N) is O(N) and is O(0.00001.N) . O(500000.N)O(N)且为O(0.00001.N)

For the same reason, O(Log(Sqrt(N))) is O(1/2.Log(N)) is O(Log(N)) , and that in any base. 出于同样的原因, O(Log(Sqrt(N)))O(1/2.Log(N))O(Log(N)) ,以及任何基数。

The big-O notation is not about the speed of your program, it is about the growth of the running time as N increases. 大O符号不是关于程序的速度,而是关于N增加的运行时间的增长。

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

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