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 > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will show you how to analyze the time and space complexity indicators in the data structure and algorithm. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
The following is mainly a detailed explanation of the underlying data structure and algorithm, focusing on several dimensions of measurement.
1. Best-case and worst-case time complexity
The best-case time complexity is, ideally, the time complexity of executing a piece of code. For example, if there are 10 elements in an array, we are looking for an element. When the element we are looking for happens to be the first element of the array, the corresponding time complexity is the best-case time complexity.
The worst-case time complexity is the time complexity of executing a piece of code in the worst case. As in the above example, if the element we are looking for is not in the list or in the last position, we need to traverse the entire array, so the worst-case time complexity is the worst-case complexity.
two。 Average case time complexity
We can perceive from the first above that the best-case time complexity and the worst-case time complexity correspond to the code complexity in extreme cases, and the probability of occurrence is not high. In order to better represent the average complexity, we need to introduce another concept: average time complexity, we call it average time complexity for short.
Let's analyze the average time complexity in the above example. The variable we are looking for is set to X, and its position in the array is in the case of Number1: in the 0~n-1 position of the array and not in the array. We add up the number of elements that need to be traversed in each case, and then divide it by nought 1, and then we can get the average number of elements that need to be traversed, that is, (1+2+3+.+n+n) / (nasty 1) = n (nau3) / 2 (nimble 1)
We know from the previous section that the coefficient, low order and constant can be omitted in the large O marking method of time complexity, so the average time complexity after simplification is O (n).
The above is how to analyze the whole content of the time and space complexity index in the data structure and algorithm. for more content related to how to analyze the time and space complexity index in the data structure and algorithm, you can search the previous article or browse the following article to learn! I believe the editor will add more knowledge to you. I hope you can support it!
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.