以下功能的时间复杂度是多少?

void fun(int n, int k)
{
    for (int i=1; i<=n; i++)
    {
      int p = pow(i, k);
      for (int j=1; j<=p; j++)
      {
          // Some O(1) work
      }
    }
}

  

上述函数的时间复杂度可以写为1 k + 2 k + 3 k + ... n1 k。

让我们试试几个例子:

k =
Sum =  +  +  ... n
    = n(n + )/
    = n 

k =
Sum =   +   +   + ... n1 。
    = N(N + )(2N + )/
    = N + N + N/ 

K =
Sum=   +   +   + ... N1 。
    = N)
    = N +N +N 

通常,渐近值可以写为(nk+ 1)/(k + 1)+Θ(nk

请注意,在像Θ这样的渐近符号中,我们总是可以忽略低阶项。

所以时间复杂度是Θ((n k + 1 )/(k + 1))。

Time Complexity of Loop with Powers的更多相关文章

  1. Leetcode: Circular Array Loop

    You are given an array of positive and negative integers. If a number n at an index is positive, the ...

  2. Instant Complexity - POJ1472

    Instant Complexity Time Limit: 1000MS Memory Limit: 10000K Description Analyzing the run-time comple ...

  3. 三部曲二(基本算法、动态规划、搜索)-1004-Instant Complexity

    Instant Complexity Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  4. The Brain vs Deep Learning Part I: Computational Complexity — Or Why the Singularity Is Nowhere Near

    The Brain vs Deep Learning Part I: Computational Complexity — Or Why the Singularity Is Nowhere Near ...

  5. Instant Complexity(模拟,递归)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1535   Accepted: 529 Description Analyz ...

  6. [LeetCode] Circular Array Loop 环形数组循环

    You are given an array of positive and negative integers. If a number n at an index is positive, the ...

  7. [Swift]LeetCode457. 环形数组循环 | Circular Array Loop

    You are given an array of positive and negative integers. If a number n at an index is positive, the ...

  8. Use JPath but not recursively loop a JObject to modify the values.

    I am dealing with a Json file, I parsed it into jObject, I have another list which flattened the pro ...

  9. [LeetCode] 457. Circular Array Loop 环形数组循环

    You are given a circular array nums of positive and negative integers. If a number k at an index is ...

随机推荐

  1. .net 系列:并发编程之一 并发编程的初步理论

    一.关于并发编程的几个误解 1)并发就是多线程 实际上多线程只是并发编程的一种形式而已,在C#中还有很多其他的并发编程技术,包括异步编程,并行编程,TPL数据流,响应式编程等.  2)只有大型服务器才 ...

  2. memcached一致性哈希及php客户端实现

    1.memcached分布式算法 memcached的分布式是依靠客户端的算法来实现,假设键名为$key,服务器数量为N,常规的实现方式有两种: 取模哈希 crc32($key)%N,通过这个算法将键 ...

  3. Unity灯光烘焙

    Unity3D烘焙技术 一.Light灯光场景烘焙1.理论理解:(1)烘焙背景:在一个场景中,由于灯光组件起到实时渲染的效果,并直接与计算机硬件GPU渲染器进行交互作用,因此对计算机显卡性能不良,以至 ...

  4. ThinkPHP中处理Layout模板的问题

    ThinkPHP中的模板引擎内置了布局模板功能支持,可以方便实现嵌套. 其中有两种布局方式,一种为以布局模板为入口的布局方式,但是需要开启LAYOUT_ON 参数(默认不开启) 并且设置布局入口文件名 ...

  5. ES 入门之一 安装ElasticSearcha

    安装ElasticSearcha 学习ES也有快一个月了,但是学习的时候一直没有总结.以前没有总结是因为感觉不会的很多,现在对ES有一点了解了.索性就从头从安装到使用ES做一个详细的总结,也分享给其他 ...

  6. Spring-MVC理解之一:应用上下文webApplicationContext

    一.先说ServletContext javaee标准规定了,servlet容器需要在应用项目启动时,给应用项目初始化一个ServletContext作为公共环境容器存放公共信息.ServletCon ...

  7. 逆向实用干货分享,Hook技术第二讲,之虚表HOOK

    逆向实用干货分享,Hook技术第二讲,之虚表HOOK 正好昨天讲到认识C++中虚表指针,以及虚表位置在反汇编中的表达方式,这里就说一下我们的新技术,虚表HOOK 昨天的博客链接: http://www ...

  8. CDH升级

    升级主要分为两部分1.CM的升级.2.CDH的升级 CM的升级 两种升级方法 1.使用package 2.使用Tarballs升级方法,参照官方升级指引,Tarball中包含了Cloudera Man ...

  9. hdu 2669 Romantic 扩展欧几里得

    Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisf ...

  10. Koltin——最详细的可见性修饰符详解

    在Kotlin中,不管是类,对象,接口,构造函数,函数,属性及其设置器都具有可见性修饰符.Kotlin中的可见性修饰符共四种.即public.protected.private.internal.在不 ...