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

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. C语言之随机数

    #include<stdio.h>#include<stdlib.h>#include<time.h>int main(){ srand(time(0)); int ...

  2. php获取当前月与上个月月初及月末时间戳的方法

    php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日.上周.本月的起始 ...

  3. 问题记录-运行Tomcat,项目程序没有响应

    问题描述:运行Tomcat,项目程序没有响应原因在于 修改成一致路径即可解决.

  4. Mysql主从原理

    MySQL的Replication(英文为复制)是一个多MySQL数据库做主从同步的方案,特点是异步复制,广泛用在各种对mysql有更高性能.更高可靠性要求的场合.与之对应的是另一个同步技术是MySQ ...

  5. Nginx均衡TCP协议服务器案例

    Nginx在企业运维中通常用来均衡HTTP协议,例如我们熟知的80.8080.8081等服务.因为大部分的服务都是http请求访问协议,那有时候需要用到TCP协议,如果来实现均衡呢? 默认nginx不 ...

  6. (一)—Linux安装与硬盘分区

    相信很多人对linux充满了喜爱,尤其是技术人员,玩惯了windows更想尝试一下这个系统.关于它的优点多多,当然,你的好你的坏,用过才明白!下面我这个菜鸟也来玩装个玩玩. 我不会那么冲动,上来就把自 ...

  7. 企业级Tomcat安全管理优化方案

    telnet管理端口保护 1. 修改默认的8005管理端口为不易猜测的端口(大于1024): <Server port=" shutdown="dangerous" ...

  8. JavaWeb学习总结(三)——Tomcat服务器学习和使用(二)(转)

    转载自 http://www.cnblogs.com/xdp-gacl/p/3744053.html 一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWe ...

  9. google protocol buffer的原理和使用(四)

    有个电子商务的系统(如果用C++实现).当中的模块A须要发送大量的订单信息给模块B.通讯的方式使用socket. 如果订单包含例如以下属性: ----------------------------- ...

  10. 设置Eclipse的workspace路径

    首次启动Eclipse/MyEclipse时, 会弹出"Workspace Launcher"对话框, 提示设置Workspace路径. 设定好路径后, 若勾选了"Use ...