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

What are the sorts of Python and their functions?

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

What is the sort of Python and its role, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

1. Bubbling sort

Bubble sort is called bubble sort precisely because each element of this sorting algorithm can move to one side of the array like a small bubble, according to its own size. Repeatedly visit the sequence to be sorted, compare two elements at a time, and swap them if the order is wrong. The work of visiting the sequence is repeated until there is no need for swapping, that is, the sequence has been sorted. The algorithm gets its name because smaller elements slowly "float" to the top of the sequence by swapping.

two。 Quick sort

Quick sorting is an improvement of bubble sorting algorithm. Like bubble sort, quick sort belongs to exchange sort, which achieves the purpose of sorting by comparing and exchanging positions between elements. The difference is that bubble sort bubbles only one element to one end of the sequence in each round, while quick sort selects a base element in each round and moves other elements larger than it to one side of the sequence, while smaller elements move to the other side of the sequence, thus breaking the sequence into two parts.

3. Insert sort

Although the code implementation of insertion sorting is not as simple and rough as bubbling sorting and selective sorting, the principle is the easiest to understand. Insertion sorting is one of the simplest and most intuitive sorting algorithms, which works by building an ordered sequence. scan the unsorted data from back to front in the sorted sequence, find the corresponding position and insert it. Like bubble sort, insert sort has an optimization algorithm called split-and-half insert.

4. Hill ranking

Hill sort is a more efficient and improved version of insert sort, which aims to improve insert sort in order to speed up, exchange non-adjacent elements to sort the local array, and finally use insert sort to sort the locally ordered array. Hill sorting is to group records according to a certain increment of subscript and sort each group using the direct insertion sorting algorithm; as the increment decreases gradually, each group contains more and more keywords, and when the increment is reduced to 1, the whole file is divided into a group. the algorithm is terminated.

5. Merge and sort

Merge sorting is an effective sorting algorithm based on merge operation. This algorithm is a very typical application of divide-and-conquer Divide and. As a typical algorithm application of divide-and-conquer idea, merge sorting can be realized in two ways: top-down recursion and bottom-up iteration.

6. Heap sort

Heap sorting is a sort algorithm designed by using the data structure of heap. Stacking is a structure similar to a complete binary tree and satisfies the property of stacking at the same time, that is, the key value or index of a child node is always less than (or greater than) its parent node. Heap sorting can be said to be a selective sort that uses the concept of heap to sort. There are two methods: large top heap: the value of each node is greater than or equal to the value of its child node, which is used in ascending order in heap sorting algorithm; small top heap: the value of each node is less than or equal to the value of its child node, used in descending order in heap sort algorithm

7. Counting and sorting

The core of counting sorting is to convert the input data values into keys and store them in the extra array space. As a sort of linear time complexity, counting sorting requires that the input data must be integers with a definite range.

8. Bucket sort

Bucket sort is an updated version of count sort. It makes use of the mapping relationship of the function, and whether it is efficient or not lies in the determination of the mapping function. In order to make bucket sorting more efficient, we need to do these two things: in the case of sufficient extra space, we need to increase the number of buckets as much as possible, and the mapping function can evenly distribute the input N data to K buckets, at the same time, for the sorting of elements in the bucket, the choice of comparison sorting algorithm is very important to the performance.

9. Cardinality sort

Cardinal sorting is a non-comparative integer sorting algorithm, its principle is to cut integers into different digits, and then compare them according to each digit. Because integers can also express strings and floating-point numbers in a specific format, cardinality sorting is not limited to integers.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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