当前位置:网站首页>时间复杂度
时间复杂度
2022-07-28 16:02:00 【竹林观月】
一、时间复杂度
1.定义
分析算法的执行效率
2.常见类型与例子
O(1)<O(logn)<O(n)<O(nlogn)<O(n²)<O(2^n)<O(n!)
O(1)
int fun(int n)
{
int i = n;
int j = n +1;
return i + j;
}
O(logn)
int fun(int n)
{
int i = 1;
while (i <= n)
{
i = i * 2;
}
return i ;
}
O(n)
int fun(int n)
{
int a = 0;
for (int i = 0; i < n; i++)
{
a += i;
}
return a ;
}
O(nlogn)
int fun(int n)
{
int a = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
a += i * j;
j = j * 2;
}
}
return a ;
}
O(n²)
int fun(int n)
{
int a = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
a += (i+j);
}
}
return a ;
}
O(2^n)
void BubbleSort(int* a, int len)
{
int temp;
for (int i = 1; i < len; ++i)
{
for (int j = len - 1; j >= i; --j)
{
if (a[j] > a[j + 1])
{
a[j] = temp;
a[j]=a[j + 1];
a[j + 1] = temp;
}
}
}
}
边栏推荐
猜你喜欢

Several methods of HyperMesh running script files

Ansa secondary development - Introduction to interface development tools

结构化设计的概要与原理--模块化

Wake up after being repeatedly upset by MQ! Hate code out this MQ manual to help the journey of autumn recruitment

【深度学习】:《PyTorch入门到项目实战》第二天:从零实现线性回归(含详细代码)

MySQL5.7及SQLyogV12安装及使用破解及常用命令

Sort 5-count sort

Interesting kotlin 0x07:composition

IM即时通讯开发优化提升连接成功率、速度等

FX3开发板 及 原理图
随机推荐
Interesting kotlin 0x07:composition
【JS】1394- ES2022 的 8 个实用的新功能
Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
Interesting kotlin 0x09:extensions are resolved statically
Is smart park the trend of future development?
【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)
[JS] eight practical new functions of 1394-es2022
配置web服务器步骤详细记录(多有借鉴)
重置grafana登录密码为默认密码
WSL+Valgrind+Clion
给定正整数N、M,均介于1~10 ^ 9之间,N <= M,找出两者之间(含N、M)的位数为偶数的数有多少个
有趣的 Kotlin 0x08:What am I
微软:Edge 浏览器已内置磁盘缓存压缩技术,可节省空间占用且不降低系统性能
LwIP develops | socket | TCP | keepalive heartbeat mechanism
Oracle system composition
排序1-插入排序与希尔排序
微软100题-天天做-第11题
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 j.journey 0-1 shortest path
Ansa secondary development - build ansa/meta secondary development environment on pycharm
Simple addition, deletion, modification and query of commodity information