In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the time complexity and space complexity of web algorithm is what related knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that you read this web algorithm time complexity and space complexity is what the article will have a harvest, let's take a look.
Algorithm is a set of methods used to manipulate data and solve program problems. For the same problem, using different algorithms, the final result may be the same, but the resources and time consumed in the process will be very different.
So how should we measure the advantages and disadvantages of different algorithms?
It is mainly considered from the two dimensions of "time" and "space" occupied by the algorithm.
Time dimension: refers to the time it takes to execute the current algorithm, which is usually described as "time complexity".
Spatial dimension: refers to how much memory is required to implement the current algorithm, which is usually described as "space complexity".
Therefore, the efficiency of an algorithm is mainly evaluated by its time complexity and space complexity. However, sometimes time and space are "fish and bear's paw", and we can't have both, so we need to strike a balance.
Now I would like to introduce the calculation methods of "time complexity" and "space complexity" respectively.
1. Time complexity
We want to know the "time complexity" of an algorithm, and the first thing that comes to mind is to run the algorithm program over and over again, then the time it takes will naturally be known.
Is this all right? Of course, but it also has many disadvantages.
This approach is very easily affected by the running environment, and the result of running on a high-performance machine is very different from that of running on a low-performance machine. It also has a lot to do with the size of the data used in the test. Moreover, when we write the algorithm, there is no way to run it completely.
Therefore, a more general method comes out: "Big O symbol representation", that is, T (n) = O (f (n))
Let's first look at an example:
For (iTunes 1; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.