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

Example Analysis of python Bubble sorting algorithm

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the python bubble sorting algorithm example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

1. Execution efficiency, which is divided into minimum time complexity, maximum time complexity and average time complexity.

Minimum time complexity: easy to calculate, the best case is that the data is ordered from the beginning, so it can be done in one bubble, and the time complexity is O (n).

Maximum time complexity: it is also easy to calculate, and the worst-case scenario is that the data is inverted at the beginning, so it can be completed by bubbling once, and the time complexity is O (n ^ 2).

Average time complexity, strictly speaking, average time complexity is the weighted average expected time complexity, analysis should be combined with the knowledge of probability recognition, for the array containing n data, there is n! The execution time of bubble sorting must be different in different sorting methods and different arrangements. if the average time complexity is to be quantitatively analyzed by the method of probability recognition, the data reasoning involved will be very complicated. This paper analyzes it through the two concepts of order degree and reverse order degree. The degree of order is the number of ordered elements. For example, the degree of order of the three data is 1, that is, (1) one, on the contrary, the degree of reverse is 2, that is, (3) (3) (2) (3), the degree of order of the three data is 3: (1) (1) (1) (2) (2) (2), and the degree of reverse is 0. The degree of order of a completely ordered data sequence is also called the degree of full order.

2. Memory consumption. Measured by the complexity of space, bubble sorting requires only one variable.

Tmp stores the exchange data, so the space complexity is O (1) and the space complexity is O (1), which is also called the original sorting algorithm.

3. Stability.

For the sorting algorithm, there is an important measure of stability, the concept is that if there are equivalent elements in the sequence to be sorted, the original order of the equivalent elements remains unchanged after sorting. Suppose there is a sequence 4Jing 1je 2jue 2, and the first 2 is called 2pm, and the second 2 is called 2pm. If it is sorted to be 1Q 2Q 2Q 2Q 4, then the sorting algorithm is stable, otherwise it is unstable.

Thank you for reading this article carefully. I hope the article "sample Analysis of python Bubble sorting algorithm" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report