时间复杂度和空间复杂度
来源:互联网 发布:diffrac.eva软件下载 编辑:程序博客网 时间:2024/04/20 02:54
时间复杂度
时间复杂度简单的理解就是执行语句的条数。如果有循环和递归,则忽略简单语句,直接算循环和递归的语句执行次数。
比如:
- 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和y
- int x=1, y=2;
- int temp = x;
- x = y;
- y = temp;
0 0
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- 时间复杂度和空间复杂度
- iPhone通讯录联系人的增加、删除、修改的操作
- 开通CSDN账户了 以后求高手带
- hdu 2089 不要62--数位dp入门
- 使用自定义的tableViewCell- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
- 面向对象的延迟绑定static
- 时间复杂度和空间复杂度
- WP8/WP8.1版网易新闻更新:首页大改版
- poj2115(扩展欧几里得运用)
- git学习
- iOS逆向----调试之艰辛路
- Composite 的setBound
- Algorithm学习笔记 --- 迷宫问题
- 写给C语言初学者的话
- webview 简单应用