当前位置:网站首页>Big O notation interpretation
Big O notation interpretation
2022-06-13 10:30:00 【edui】
When comparing the performance of the algorithm , It is not only related to the speed and space of the same data item , What is more important is the degree of change with the data items when the data volume changes , Big O Recording and sending is the curve of the time complexity and space complexity of the algorithm changing with the data item , Because the shape of a polynomial curve is usually determined by the highest order term , When the amount of data is relatively high, the influence of the lower order term is very small relative to the highest order term, which can be ignored for convenience .
- Time complexity :
Simply put, the time complexity increases with N An increase in , The number of times the program needs to run varies with N The curve of change . A function in the algorithm has n Repeat the basic operation for times , use T(n) Express , Now there is some auxiliary function f(n), Properly n Approaching infinity ,T(n)/f(n) The limit value of is a constant not equal to zero , said f(n) yes T(n) Functions of the same order of magnitude of . Write it down as T(n)=O(f(n)), call O(f(n)) Is the incremental time complexity of the algorithm , Time complexity
Take a simple chestnut :
sum=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
sum++;
First line frequency 1, The second line n, The third line n², In the fourth row n²,T(n)=2n²+n+1 =O(n²) The time complexity is
O(n²)
- Spatial complexity :
The space complexity of an algorithm is defined as the storage space consumed by the algorithm , The consumption of storage space is determined by the number of objects created in the function , That is, the spatial complexity depends on the number of objects created in the function, and the calculation method of time complexity is similar . In recursion, each recursion always uses space and N Approximate curvilinear relationship of .
for example :
int fun(int n)
{
int num = 1;
if(n <= num )
return 1;
else
return n*fun(n-1);
}
Recursive space complexity :
O(n)=n*1=n;
The number of recursions is n Time , Every time you enter create 1 Objects
summary , Big O The advantage of memorization is simplicity , Understandability , But the disadvantage is that it is too simple , such as O(n) and O(5n) It is the same. It is also recorded as O(n), So when the amount of data is the same, obviously O(n) Faster , Recognizing this is more accurate in algorithm analysis .
边栏推荐
猜你喜欢

C Oracle multi table query

实战模拟│企业微信机器人实时报错预警

matlab轮毂电机分析模糊pid控制垂向振动分析

WIN7无法被远程桌面问题
![[image denoising] image denoising based on MATLAB Gaussian + mean + median + bilateral filtering [including Matlab source code 1872]](/img/8d/3c2664738ad5ab11a35b7aadc8eb88.png)
[image denoising] image denoising based on MATLAB Gaussian + mean + median + bilateral filtering [including Matlab source code 1872]

虚拟机内存结构简述

Node-RED系列(二四):在Node-RED中使用mysql节点实现数据库的增删改查

Electrolytic capacitor, tantalum capacitor, ordinary capacitor

Sunyuchen, head of Grenada delegation, attended the WTO MC12 and emphasized the development of digital economy

Install Kubernetes 1.24
随机推荐
逐向双碳:东数西算中的绿色需求与竞争焦点
Interrupt handling mechanism
Thingsboard tutorial (20): filtering telemetry data using regular chains
Docker deployment MySQL
一文读懂简单查询代价估算【这次高斯不是数学家】
Pytorch basis (II) -- tensor and gradient
MySQL到底怎么优化?
[bearing fault decomposition] ITD bearing fault signal decomposition based on MATLAB [including Matlab source code 1871]
关于#数据库#的问题:反复检查过了查不出来
技术管理进阶——管理者可以使用哪些管理工具
Simple query cost estimation [Gauss is not a mathematician this time]
检验冗余码是否出错题型解法-摘录
Cynthia project defect management system
IDEA远程调试spark-submit提交的jar
第一章 第一节
index查list 注入的是mysql 执行的是oracle
Double carbon in every direction: green demand and competition focus in the calculation from the east to the West
Oracle custom data type question
Knowledge points of silicon steel sheet
MySQL利用E-R模型的数据库概念设计