Time Complexity of Loop with Powers
以下功能的时间复杂度是多少?
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的更多相关文章
- Leetcode: Circular Array Loop
You are given an array of positive and negative integers. If a number n at an index is positive, the ...
- Instant Complexity - POJ1472
Instant Complexity Time Limit: 1000MS Memory Limit: 10000K Description Analyzing the run-time comple ...
- 三部曲二(基本算法、动态规划、搜索)-1004-Instant Complexity
Instant Complexity Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- 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 ...
- Instant Complexity(模拟,递归)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1535 Accepted: 529 Description Analyz ...
- [LeetCode] Circular Array Loop 环形数组循环
You are given an array of positive and negative integers. If a number n at an index is positive, the ...
- [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 ...
- 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 ...
- [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 ...
随机推荐
- Less 编译工具
Less 编译工具 虽然你可以选择在浏览器端使用Less,直接在页面中嵌入一个 Less.js 文件,你也可以选择在服务器端使用Less,使用命令行将Less文件编译成最终的CSS文件. 然而,这两种 ...
- CentOS环境下Docker私有仓库搭建
本文讲述如何搭建docker私有仓库. 有了docker hub,为什么还要搭建docker私有仓库? 1.性能考虑:docker hub的访问要通过互联网,性能太低. 2.安全性:更多的时候,镜像不 ...
- js实现关键词高亮显示 正则匹配
html 和ajax 部分就不写了,只需将需要匹配的文字传进去就可以了 比如匹配后台传回的字符串data.content中的关键词:直接调用: data.content = highLightKeyw ...
- CCF-201403-1-相反数
问题描述 试题编号: 201403-1 试题名称: 相反数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 有 N 个非零且各不相同的整数.请你编一个程序求出它们中有多少对相反 ...
- mysql 存储过程 小实例
咱们先建个表吧 [SQL] 纯文本查看 复制代码 ? 1 2 3 4 5 6 CREATE TABLE `test1` ( `id` int(10) unsigned NOT NULL A ...
- php面试之数据结构和算法
二.数据结构和算法 1.使对象可以像数组一样进行foreach循环,要求属性必须是私有.(Iterator模式的PHP5实现,写一类实现Iterator接口)(腾讯) <?php class T ...
- 音频传输之Jitter Buffer设计与实现
在语音通信中Jitter Buffer(下面简称JB)是接收侧一个非常重要的模块,它是决定音质的重要因素之一.一方面它会把收到的乱序的语音包排好序放在buffer里正确的位置上,另一方面它把接收到的语 ...
- .9-浅析webpack源码之NodeEnvironmentPlugin模块总览
介绍Compiler的构造比较无趣,不如先过后面的,在用到compiler的时候再做讲解. 这一节主要讲这行代码: // 不管这里 compiler = new Compiler(); compile ...
- 转载 Mysql安装过程
目录 一.概述 二.MySQL安装 三.安装成功验证 四.NavicatforMySQL下载及使用 一.概述 MySQL版本:5.7.17 下载地址:http://rj.baidu.com/soft/ ...
- VisualStudio程序运行后控制台窗口一闪就没了
这个虽然是千查万查出来的,但也不是原创的.希望对大家有所帮助. 方案一:网上最常见的解决方案是,在程序结尾的 return 0; 之前加 system("pause") 或 get ...