时间复杂度和空间复杂度
来源:互联网 发布:淘宝瞄准镜 编辑:程序博客网 时间:2024/04/27 06:07
时间复杂度
时间复杂度简单的理解就是执行语句的条数。如果有循环和递归,则忽略简单语句,直接算循环和递归的语句执行次数。
比如:
int x = 1;//时间复杂度为O(1)for(int i=0; i<n; i++) {System.out.println(i);}//时间复杂度为O(n)具体例子:
1、O(1)
int x = 1;
2、O(n)
for(int i=0; i<n; i++) {System.out.println(i);}
3、O()
int n = 8, count = 0;;for(int i=1; i<=n; i *= 2) {count++;}
4、
int n = 8, count = 0;;for(int i=1; i<=n; i++) {for(int j=1; j<=n; j++) {count++;}}
5、
int n = 8, count = 0;;for(int i=1; i<=n; i *= 2) {for(int j=1; j<=n; j++) {count++;}}
所举例子都比较简单。
空间复杂度
空间复杂度也很简单的理解为临时变量占用的存储空间。一个简单例子:
//交换两个变量x和yint x=1, y=2;int temp = x;x = y;y = temp;一个临时变量temp,所以空间复杂度为O(1)。
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- Climbing Stairs 爬楼梯 @LeetCode
- Inline Hook(ring3) 简单源码
- 将毫秒值转化为时间(java)
- oracle forall
- 经典电影台词系列【1】——死亡笔记
- 时间复杂度和空间复杂度
- soj 1152,1153 马的周游问题
- 经典电影台词系列【2】——灵异第六感
- SqlMapConfig.xml---在spring配置文件中自动加载的mybatis文件
- paip.python ide eric5-5.3.7 安装以及建立项目使用 最佳实践
- paip. sip module implements API v10.0 to v10.1 but the PyQt4.QtCore module requires API v9.2
- java注释以及javadoc jar 生成
- 经典电影台词系列【3】——无间道
- Eclipse中javadoc的使用以及中文乱码的解决