当前位置:网站首页>Time complexity
Time complexity
2022-07-28 16:57:00 【Watching the moon in the bamboo forest】
List of articles
One 、 Time complexity
1. Definition
Analyze the execution efficiency of the algorithm
2. Common types and examples
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;
}
}
}
}
边栏推荐
- ERROR: transport library not found: dt_ socket
- "Weilai Cup" 2022 Niuke summer multi school training camp 3 h.hacker sam+ segment tree /dp/ divide and conquer (without the largest sub segment and of the inspection interval)
- Oracle table partition
- egg(十九):使用egg-redis性能优化,缓存数据提升响应效率
- Implementation of paging
- leetcode70假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
- Is smart park the trend of future development?
- Programmers from entry to roast!!!!
- 在AD中添加差分对及连线
- 小程序:scroll-view默认滑倒最下面
猜你喜欢

【深度学习】:《PyTorch入门到项目实战》第一天:数据操作和自动求导

Interesting kotlin 0x07:composition

关于 CMS 垃圾回收器,你真的懂了吗?

Configure HyperMesh secondary development environment on vs Code

【指针内功修炼】字符指针 + 指针数组 + 数组指针 + 指针参数(一)

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

Tcp/ip related

【深度学习】:《PyTorch入门到项目实战》第九天:Dropout实现(含源码)

Some suggestions on optimizing HyperMesh script performance

egg(十九):使用egg-redis性能优化,缓存数据提升响应效率
随机推荐
HyperMesh auto save (enhanced) plug-in instructions
Leetcode647. Palindrome substring
Hdu1847 problem solving ideas
Interesting kotlin 0x08:what am I
阿里云-武林头条-建站小能手争霸赛
Introduction and implementation of stack (detailed explanation)
parseJson
Multiple commands produce '... /xxx.app/assets.car' problem
Applet: scroll view slides to the bottom by default
结构化设计的概要与原理--模块化
Asp.net large file block upload breakpoint resume demo
parseJson
QT designer for QT learning
Optimization of network request success rate in IM instant messaging software development
Redis系列4:高可用之Sentinel(哨兵模式)
Fx3 development board and schematic diagram
Outline and principle of structured design -- modularization
关于Bug处理的一些看法
asp.net大文件分块上传断点续传demo
Learn to use MySQL explain to execute the plan, and SQL performance tuning is no longer difficult