Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Time complexity and efficiency of algorithm (2)

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Today, let's take a look at the complexity and efficiency of the algorithm. when judging the efficiency of an algorithm, the constant terms and other secondary terms in the number of operations can often be ignored, and we only need to pay attention to the highest-order terms to draw a conclusion. So how do we use symbols to qualitatively judge the efficiency of the algorithm? The complexity of the algorithm is divided into two parts: 1, time complexity, that is, the qualitative description of the time demand after the algorithm is running; 2, space complexity, that is, the qualitative description of the space demand after the algorithm is running.

The data structure focuses on the efficiency of the algorithm, so we will focus on the time complexity of the algorithm later, but the method used can be used to judge the space complexity! We often use the large O representation to analyze the time complexity of the algorithm. Next to explain this method, the efficiency of the algorithm depends heavily on the number of operations (Operation); the estimation of the number of operations can be used as an estimation of time complexity; in the judgment, we first pay attention to the highest number of operations. As follows:

Let's analyze the common time complexity:

1. Linear order time complexity: O (n). As follows:

2. Logarithmic time complexity: O (logn). As follows

3. Square order time complexity: O (n ²). As follows:

Let's take a look at the common time complexity, as shown in the following figure

A common comparison of time complexity is as follows

Let's analyze the complexity of the following function program through an example.

Int find (int a [], int n, int v) {int ret =-1; for (int iTuno; 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report