当前位置:网站首页>Time complexity
Time complexity
2022-06-23 01:11:00 【Constant constant baa】
Time complexity
1. Constant time operation
If an operation has nothing to do with the data volume of the sample , Every time is a fixed time to complete the operation , This operation is called a constant operation .
Example :int a=arr[i]; a take i The number of positions is taken out , Is a fixed time , And arr It doesn't matter the amount of data , This is a constant operation .
conversely ,int b =list.get[i]; It's a linked list ,b Values need to be taken one by one from the beginning of the linked list ,i In the thousands , Just check how many people , It's about the amount of data , Not a constant operation .
Add, subtract, multiply and divide , Bit operations are all constant operations .
2. Time complexity
Time complexity is an algorithm flow , An indicator of the number of constant operations . Commonly used o Express , pronounce as big o.
say concretely , How many constant operations are performed in an algorithm flow ( use N Express ), Sum up the quantitative expression of constant operation (N The expression of ), Only the highest order terms are left , And not the coefficient of the highest order term , If the rest is f(N), So the time complexity is o(f(N)).
3. Evaluate the algorithm flow
Evaluate the flow of an algorithm , Let's look at the time complexity index first , Highest order items . If the same , Then analyze the actual running time under different data samples , That is to say “ Constant term time ”.( Just look at N The coefficient of the expression , If you N1 yes 10,N2 yes 100, however N2 Of 100 There are many bit operations in ,N1 Of 10 Middle is addition, subtraction, multiplication and division , Can't directly because 10<100 Just say N1 Better algorithm , Because the constant operation time of addition, subtraction, multiplication and division is different from that of bit operation , Not sure , We need to experiment with the actual situation .)
Encounter the same indicators , Directly by experiment , Run the code separately to judge .
Example :
` public static void text1(){
int N =10000;
int a=0;
for(int i=0;i<N;i++){
a=12+100;
a=32*12;`
}
}
`public static void text2(){``
int N =10000;
int a=0;
for(int i=0;i<N;i++){
a=12|100;
a=746^12;
}
}
text1 and text2 The indicators of time complexity are the same N, Next, direct code tests to determine which is better , There is no need to go to the ratio coefficient .
边栏推荐
- [initial launch] there are too many requests at once, and the database is in danger
- Explain the startup process of opengauss multithreading architecture in detail
- Add / get and delete cookies
- Xiaobai operates win10 to expand Disk C (allocate disk D memory to Disk C) and the test is valid for many times
- Some thoughts about the technology of test / development programmers are very advanced, and they can't go on
- Shell view help
- Is it reliable to get new debts? Is it safe?
- How to get started with machine learning?
- 时间复杂度
- Big guys, 2.2.1 the CDC monitoring SQLSEVER can only get the full amount of data. Why can't we get the incremental data in the later period
猜你喜欢

cadence SPB17.4 - allegro - 优化指定单条电气线折线连接角度 - 折线转圆弧
![[initial launch] there are too many requests at once, and the database is in danger](/img/c1/807575e1340b8f8fe54197720ef575.png)
[initial launch] there are too many requests at once, and the database is in danger

最安全的现货白银的心理分析

E-R diagram

Cadence spb17.4 - Allegro - optimiser la spécification de l'angle de connexion de la polyligne pour une seule ligne électrique - polyligne à arc

How to set the power-off auto start of easycvr hardware box

Figure what are the uses and applications of neural networks?

贵金属现货白银如何呢?

黄金etf持仓量如何算
Yyds dry goods counting tail recursion is better than recursion
随机推荐
Have you stepped on these pits? Use caution when creating indexes on time type columns
BGP federal comprehensive experiment
关于打算做一个web的问题看板,需要使用哪些方面语言及数据库知识!
Sélecteur de hiérarchie
Overview of visual object detection technology based on deep learning
E-R diagram
Graphite statsd interface data format description
[launch] redis Series 2: data persistence to improve availability
打新债开户安全么,怎么开
Vector 1 (classes and objects)
3DMAX modeling notes (I): introducing 3DMAX and creating the first model Hello World
Development status of full color LED display
贵金属现货白银如何呢?
[sliding window] leetcode992 Subarrays with K Different Integers
Cadence spb17.4 - Allegro - optimiser la spécification de l'angle de connexion de la polyligne pour une seule ligne électrique - polyligne à arc
Figure what are the uses and applications of neural networks?
Leetcode question brushing - 715 Range module
Js--- SVG to png
C language student achievement ranking system
Add / get and delete cookies