current position：Home>How to calculate the time complexity
How to calculate the time complexity
2022-02-04 16:41:39 【CSDN Q & A】
How to calculate the time complexity ？ After reading a lot of information on the Internet, I can only see the misty , When it comes to questions, you won't be able to do them at all , Do you have any brothers and sisters to answer for me . thank you ！
for (int i = 0; i < 20; i++)
code with O(N)
for (int j = 0; j < n; j++)
code with O(1)
for (int j = 1; j < n; j = 2* j)
code with O(N)
for (int j=1;j<N;j=2*j)
code with 0(1)
Take the answer ：
The so-called time complexity , It's such a thing ：
Suppose you have a piece of code , The unit of time required to run once is 1, Or writing O（1）, The concrete is 1 individual CPU Execution cycle , still 1 minute , Is not important .
When your input value increases N After times , How much more time ？
So for a heavy for In a circle , It grows linearly , The number of cycles increases n times , Time also increases n times , So time complexity is O(N)
If it's double for loop , So that is O(N^2), Square relationship .
Specific to your problem ,
a） A typical heavy for loop
Ask you to write a time complexity is O(N) Code for , Write anything you like , Even if you don't write anything , It is O(N)
b）1) requirement for The time complexity in the loop is O(1), That is, time is not related to N relevant , That directly break Come out .
2） Ask to be j The time complexity increases linearly with exponential growth , The easiest way , Take the ride 2 Except back , again ++
c) Same as B1
Other answers 2：
Send out the topic and have a look
Other answers 3：
The algorithm basically needs a loop , Recursion, etc ,
Time complexity means that a loop is entering n( May be n Data , It can also be a single value n) The average number of cycles or recursions required for , That is, the number of times the main code is executed
author[CSDN Q & A],Please bring the original link to reprint, thank you.
The sidebar is recommended
- What is the cost description of configuring data integration tasks between RDS and MySQL?
- What are the steps to configure the data integration task between RDS and MySQL?
- What are the data skew phenomena in MapReduce?
- What is the impact of stopping data integration tasks in DTS?
- What is the difference between quick Bi and power Bi in data source connection?
- What is the implementation principle of the four features of MySQL transactions?
- What is the impact of restoring data integration tasks in DTS?
- What are the fault tolerance methods in spark?
- What is the impact of deleting data integration tasks in DTS?
- What are the implementation ideas of transaction acid feature of MySQL?
guess what you like
What is the difference between quick Bi and power Bi in data processing and modeling?
What are the operational steps for managing data integration tasks in DTS?
What are the five advantages of spark?
What are the operation steps of modifying scheduling policy in DTS?
What are the similarities and differences between MapReduce and spark?
What are the differences between quick Bi and power Bi in visual presentation and report making?
How does MapReduce specify the number of CPUs at runtime?
How to write SQL to effectively use composite index?
What is the difference between quick Bi and power Bi on the mobile end?
How does MapReduce specify the size of runtime memory?
- What is the explanation of the scheduling policy in DTS?
- What are the instructions for modifying the scheduling effective date in DTS?
- What are the instructions for modifying the scheduling cycle in DTS?
- What are the streaming data writing functions in maxcompute?
- What will happen to the database self incrementing primary key?
- How does MapReduce tune the operating system?
- What are the performance advantages of streaming data writing in maxcompute?
- What is the description of modifying the task failure policy in DTS?
- How does MySQL master-slave replication work?
- What is the technical architecture of streaming data writing in maxcompute?
- What is the background information of monitoring alarm configured in DTS?
- What are the reasons for the delay of master-slave synchronization in MySQL?
- What are the operation steps for configuring monitoring alarms in DTS?
- Server in zookeeper A = B: C: D what do they mean?
- What is the query acceleration function in maxcompute?
- What is the solution to the master-slave synchronization delay of MySQL?
- What parameters are frequently adjusted when running MapReduce tasks?
- What is the technical architecture of query acceleration in maxcompute?
- What are the operation steps of viewing historical tasks in DTS?
- In 2020, Alibaba Android classic: after getting the offer, Alibaba fished up the resume again
- Summary of common knowledge points of Android interview in 2020, HashMap traversal
- 2020android will never die. As a programmer, what do you think is the biggest sorrow
- Linux system programming 43 file descriptor
- C + + date judgment blank filling is required to complete the blank filling
- About the parameter problem in Ajax, geigei help
- The number of daffodils in C language is wrong,
- UE4 carving terrain painting display problem
- Single chip C51 assembly language scatter program error
- Hello, let me ask Prometheus how to write port rules
- How can Linux ssh server solve the following problems
- How about the Java debug mode? This is what I finally appeared.
- Linux operating system, online solution
- Calculate the value of the formula and display it on the screen
- What is the use of inter address access pointer access reference access
- There are two different pages in the front end. Add data on one page and refresh the data on the other page
- Find someone to teach me how to train somethingv2 on slowfast
- How can the statistics after pandas group by be output conditionally?
- Nlogit import data, whether in CSV or exclude format, not even the CSV format exported by Stata. Project import cannot import it
- Problems and solutions in the research and implementation of monitoring system testing in Universities Based on Servlet