In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the function of the basic algorithm of Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
What are the basic algorithms of Python? What is the function? The algorithm is the idea and implementation step of solving the problem, and programming is the realization of the algorithm, which converts the human language into a certain programming language. The common internal sorting algorithms are: insert sort, Hill sort, select sort, bubble sort, merge sort, quick sort, heap sort, cardinality sort and so on.
The algorithm refers to the accurate and complete description of the problem-solving scheme and a series of clear instructions to solve the problem. The algorithm represents the strategic mechanism of using the systematic method to describe the problem-solving mechanism. For a certain standard input, the required output can be obtained in a limited time. If an algorithm is flawed or not suitable for a problem, executing the algorithm will not solve the problem. Different algorithms may use different time, space or efficiency to accomplish the same task. The advantages and disadvantages of an algorithm can be measured by space complexity and time complexity.
First, the important characteristics of the algorithm
1. Finiteness: algorithm finiteness means that the algorithm must be able to terminate after a limited number of steps.
2. Accuracy: each step of the algorithm must be accurately defined.
3. Input: an algorithm has 0 or more inputs to depict the initial condition of the Operand. The so-called zero input means that the algorithm itself determines the initial conditions.
4. Output item: an algorithm has one or more outputs to reflect the results after processing the input data, and the algorithm without output is meaningless.
5. Feasibility: any calculation step performed in the algorithm can be decomposed into basic executable operation steps, that is, each calculation step can be completed in a limited time, which is also called validity.
2. Python basic algorithm
1. Bubble sorting
Bubble sorting is also a simple and intuitive sorting algorithm. 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.
2. 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.
3. Hill sorting
Hill sorting, also known as decreasing incremental sorting algorithm, is a more efficient and improved version of insertion sorting. But Hill sorting is an unstable sorting algorithm. Hill sorting is based on the following two properties of insert sorting: when it operates on almost sorted data, it is efficient, that is, it can achieve the efficiency of linear sorting; but insert sorting is generally inefficient because insert sorting can only move data one bit at a time. The basic idea of Hill sorting is that the whole sequence of records to be sorted is divided into several sub-sequences for direct insertion and sorting, and then all the records are directly inserted and sorted when the records in the whole sequence are "basically ordered".
4. 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 is realized by two methods: top-down recursion and bottom-up iteration.
5. Quick sort
Quick sorting is a sort algorithm developed by Tony Hall. On average, sorting n items requires nlogn comparisons. In the worst case, you need to compare (N2) times, but this is not common. In fact, quick sorting is usually significantly faster than other algorithms, because its internal loops can be implemented efficiently on most architectures. Quick sort uses the divide-and-conquer strategy to divide a series into two subseries. Quick sorting is also a typical application of divide-and-conquer idea in sorting algorithm. In essence, fast sorting should be regarded as a recursive divide-and-conquer method based on bubble sorting.
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. Count sort
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 sorting
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.
Sorting is the most commonly used application of Python algorithm in practical work. Python programmers need to understand the principles and complexity of sorting introduction, bubble sorting, selection sorting, insertion sorting, fast sorting and Hill sorting.
This is the end of the content of "what is the function of the basic algorithm of Python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.