Algorithm-fast sorting of sorting
Quick sorting is named after the efficiency of practical applications. It is almost the fastest Sorting Algorithm and is listed among the top 10 algorithms in the 20th century. Quick sorting reflects the "divide and conquer" concept of computer design. The core is to divide the entire problem into multiple small problems that are relatively easy to handle and conquer separately. Sort algorithms based on the principle of divide and conquer, as well as Hill sort algorithms.
1. Quick sorting Core: If you know how many people are in front of you and how many people are behind you, you must know where you are. Quick sorting involves the following steps: 1. Select the number of demarcation points. refer to the number of demarcation points. Place the value greater than the reference number on the right and the value less than on the left. 2. recursion of the sequence on both sides of the left and right 3. Merge the entire sequence to produce ordered results. Compared with the bubble sort [algorithm-sort one] bubble sort "bubble" image, quick sorting does not seem so appropriate. By analyzing the preceding steps, the algorithm actually determines the location of the selected demarcation number for each partition. Selected demarcation number: 8 and then split the sequence
A number smaller than 8 is larger than 8. Based on the number of numbers in the left and right boxes, you can know where the division number 8 should be placed. There are many ways to implement quick sorting. Below is an implementation:
Quick sorting is a complex sorting algorithm. It is difficult to understand quick sorting by grasping the core of the algorithm.
2. Time Complexity It is difficult to analyze the time complexity of quick sorting. You can see the results in the first place by using the recursive method:Data Count n = 1 Yes, F = 0 F (n) = n-1 + 2F (n/2) // divide the data into two values: n/2. = N-1 + 2 (n/2-1) .... = O (nlogn) This time complexity is better than bubble sort [algorithm-sort one] bubble sort. 3. space complexity The space consumption of quick sorting mainly comes from the stack consumption generated during recursive calls. Its complexity is between O (logn) and O (n.