有没有时间复杂度为O(n *(log n)^ 2)的算法?(Is there any algorithm with the time complexity of O(n*(log n)^2)?)

编程入门 行业动态 更新时间:2024-10-06 20:40:54
有没有时间复杂度为O(n *(log n)^ 2)的算法?(Is there any algorithm with the time complexity of O(n*(log n)^2)?)

我知道heapsort的时间复杂度为O(n log n) ,但我真的不能想到一个具有O(n(log n) 2 )的算法

I know that heapsort has a time complexity of O(n log n), but I can't really think of an algorithm that has one of O(n (log n)2).

最满意答案

构建一个非常容易。 最明显的例子是:

for i in xrange(n * int(log(n, 2) ** 2)): // do something O(1)

有关更有用的示例,您可以使用Master's定理来提供满足您需求的无限量递归(任何k都可以工作):

在此处输入图像描述


如果您正在寻找一个真正的算法,那么Shellsort的最坏情况复杂度为O(n(log n) 2 。 对于inplace mergesort也是如此 。

PS你正在寻找的东西的奇特名称是k = 2的拟线性时间复杂度。

It is super easy to construct one. The most obvious example is:

for i in xrange(n * int(log(n, 2) ** 2)): // do something O(1)

For a more helpful example you can use Master's theorem to come up with infinite amount of recursions that satisfy your needs (any k will work):

enter image description here


If you are looking for a real algorithm, then Shellsort has a worst case complexity of O(n (log n)2). The same for an inplace mergesort.

P.S. a fancy name for the stuff you are looking for is quasilinear time complexity with k = 2.

更多推荐

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

发布评论

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

>www.elefans.com

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