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 ...
随机推荐
- C#学习笔记——数据库篇(1)
C#的数据连接分同样分三步走 .连接语句 string str_conn = "sever = localhost;database = smaple;usid = sa;pwd = 123 ...
- Python开发目录
Python开发目录 Python之三目运算符 Python之文件的基本操作
- 第六届蓝桥杯软件类省赛题解C++/Java
第六届蓝桥杯软件类省赛题解C++/Java 1[C++].统计不含4的数字统计10000至99999中,不包含4的数值个数.答:暴力循环范围内所有数字判断一下就是了,答案是52488 1[Java]. ...
- ThinkPHP中ajax绑定select下拉框无法显示
html代码: 控制器代码: 其中的<option value="{$vo.gradeId}">{$one.gradeName}</option> 在操作过 ...
- IntelliJ IDEA(二) :面板介绍
一.面板说明 IDEA面板的全貌如下图 二.菜单栏 下面会简单介绍下一些常用的部分菜单使用,如有疑问或补充欢迎留言. (1).File文件 1. New:新建一个工程 可以新建project,导入已存 ...
- page 简单易懂 分页
基础分页功能 <?php class Page{ //$count是用户设定的值 public $a; function pages($count,$page_num,$url ...
- 深入理解javascript函数进阶系列第二篇——函数柯里化
前面的话 函数柯里化currying的概念最早由俄国数学家Moses Schönfinkel发明,而后由著名的数理逻辑学家Haskell Curry将其丰富和发展,currying由此得名.本文将详细 ...
- js 数组去重复的方法
数组去重复是js中常用的方法,归纳了四种如下: 1. for + indexOf 去重复 var arr = [3,5,5,4,1,1,2,3,7,2,5]; var target = []; fo ...
- oracle 恢复数据到某个时间点
delete from tablename;insert into tablename select * from tablename as of timestamp to_timestamp('20 ...
- db2服务器端授权
昨天吃饭回来有点晚,没有及时写,今天补上. db2服务器端安装就不说了,网上很多.今天具体说说授权吧.这是个麻烦事. 安装的时候会让你创建数据库.你就根据提 ...