当前位置:网站首页>时间复杂度
时间复杂度
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;
}
}
}
}
边栏推荐
- Multiple commands produce '... /xxx.app/assets.car' problem
- 我该如何理解工艺
- How to set ticdc synchronization data to only synchronize the specified library?
- 关于 CMS 垃圾回收器,你真的懂了吗?
- Implementation of paging
- parseJson
- 配置web服务器步骤详细记录(多有借鉴)
- Detailed record of steps to configure web server (many references)
- Ansa secondary development - Introduction to interface development tools
- HM secondary development - data names and its use
猜你喜欢

Leetcode daily practice - 160. Cross linked list

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

Ruoyi集成flyway后启动报错的解决方法

Sort 1-insert sort and Hill sort

Optimization of network request success rate in IM instant messaging software development

LeetCode-学会复杂带随机指针链表的题(详解)

【深度学习】:《PyTorch入门到项目实战》第一天:数据操作和自动求导
![[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)](/img/e8/2044cae63fe2145ce6294cb1fdfaa0.png)
[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)

【深度学习】:《PyTorch入门到项目实战》第五天:从0到1实现Softmax回归(含源码)

egg(十九):使用egg-redis性能优化,缓存数据提升响应效率
随机推荐
Text filtering skills
mysql cdc 如果binlog日志文件不全,全量阶段能读到所有数据吗
Leetcode daily practice - 160. Cross linked list
MD5加密验证
Signal and slot mechanism of QT learning
有趣的 Kotlin 0x06:List minus list
遭MQ连连干翻后的醒悟!含恨码出这份MQ手册助力秋招之旅
ticdc同步数据怎么设置只同步指定的库?
leetcode9. 回文数
How to set ticdc synchronization data to only synchronize the specified library?
微软100题-天天做-第11题
IM即时通讯软件开发网络请求成功率的优化
Applet: get element node information
Reset grafana login password to default password
LwIP develops | socket | TCP | keepalive heartbeat mechanism
Record development issues
leetcode647. 回文子串
LeetCode每日一练 —— 160. 相交链表
记录开发问题
Learn to use MySQL explain to execute the plan, and SQL performance tuning is no longer difficult