In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to achieve selection sorting in Python, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.
Select sort (Selection Sort)
Selection Sort is an improvement based on bubble sorting, which retains multiple comparisons in bubble sorting, and each trip still moves the largest item to the end. The difference is that the bubble sort compares each adjacent element whether it needs to be swapped or not, but the selective sort is the index that records the maximum value, which is swapped with the last element after traversing the list of the current trip.
Select the number of comparisons for sorting time complexity: O (n ^ 2)
Select the number of exchanges for sorting time complexity: O (n)
Bubble sort: Python data structure and algorithm-Bubble sort
Select sort key: record the maximum item location
The idea of the algorithm:
1. The first selection sort: nMel 1 comparison, record the location of the largest item, exchange with the last element
two。 The second selection sort: 1 element of NMUE, 2 comparisons of NMUE, record the position of the largest item, and exchange with the last element of the current trip.
3. The third trip is sorted by selecting 2 elements, comparing 3 times, recording the position of the largest item, and exchanging with the last element of the current trip.
……
NMUE 1. N-1 th selection sort: direct comparison of 2 elements
On how to achieve selection sorting in Python to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.