Sorting method
By selecting the first element of the array to be sorted as the benchmark element, the data is divided and recursively sorted, the performance degradation problem of the prior art when the data is partially ordered or contains a large number of repetitions is solved, and a more efficient sorting process is achieved.
Patent Information
- Application Number
- CN202510112994.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-05-27
AI Technical Summary
The existing sorting method has degraded performance when the data is partially ordered or contains a large number of repetitive elements, resulting in a longer sorting time.
Using an improved sorting method, by selecting the first element of the array to be sorted as the benchmark element, traversing the array, dividing the elements into two sets smaller than and greater than or equal to the benchmark elements, and recursively sorting the two sets respectively until the number of elements in the set is less than or equal to 1.
When the data is partially ordered or contains a large number of repetitive elements, the sorting efficiency is significantly improved. Compared with the eight basic algorithms, it has obvious advantages and can discharge the order of large amounts of data in a shorter time.
Smart Images

Figure CN120045156A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data sorting, and particularly to a sorting method. Background Art
[0002] In modern data processing, sorting operations are a fundamental and crucial task. With the continuous growth of data volume, the performance of sorting algorithms plays a decisive role in the efficiency of the entire data processing system. Currently, there are already a variety of basic sorting algorithms, such as quicksort, bubble sort, insertion sort, merge sort, selection sort, heap sort, shell sort, etc. These algorithms have their own advantages and disadvantages in different application scenarios. Among them, quicksort is a commonly used and efficient sorting algorithm. Its basic principle is to select a pivot element (usually the first element of the array), divide the elements in the array into two parts, those less than the pivot element and those greater than the pivot element, and then recursively sort these two parts separately.
[0003] In existing sorting methods, in some special data distribution cases, such as when the data is partially sorted or contains a large number of duplicate elements, there may be problems of performance degradation. The number of comparison and swap operations is relatively large, resulting in a longer sorting time. Summary of the Invention
[0004] The object of the present invention is to provide a sorting method, which solves the technical problem that in some special data distribution cases, such as when the data is partially sorted or contains a large number of duplicate elements, there may be problems of performance degradation, and the number of comparison and swap operations is relatively large, resulting in a longer sorting time.
[0005] In order to achieve the above object of the invention, the technical solution adopted by the present invention is as follows:
[0006] A sorting method, characterized by comprising the following steps: Step 1, receiving an array to be sorted: obtaining the array data to be sorted;
[0007] Step 2, selecting a pivot element: determining the first element of the array to be sorted as the only pivot element;
[0008] Step 3, element classification: traversing the other elements in the array except the pivot element, and dividing the elements into two sets according to the size relationship with the pivot element. The elements less than the pivot element are classified into the first set, and the elements greater than or equal to the pivot element are classified into the second set;
[0009] Step 4, recursive sorting: recursively executing the above sorting method on the first set and the second set respectively until the number of elements in the set is less than or equal to 1;
[0010] Step 5, result merging: combining the sorted first set, the pivot element, and the sorted second set in sequence to form the final ordered array.
[0011] As an improvement, in each round of recursive sorting operation, the first element of the current sub-array to be sorted is used as the pivot element for element classification.
[0012] As an improvement, in the element classification step, the comparison between the element and the pivot element is a strict comparison. When the element is equal to the pivot element, it is classified into the second set that is greater than or equal to the pivot element.
[0013] As an improvement, during the recursive sorting process, the sorting logic called is consistent with the logic of the overall sorting method.
[0014] The beneficial effects of the present invention are: sorting a large amount of data in a shorter time, improving the sorting efficiency of the data, and having obvious advantages compared with the eight basic algorithms. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a schematic diagram of the steps of the sorting method of the present invention;
[0016] Figure 2 It is a schematic diagram that all codes of the sorting method of the present invention run in the Python environment;
[0017] Figure 3 It is a schematic diagram of the quicksort algorithm and its running time of the sorting method of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0018] As Figure 1 shown, the sorting method is characterized by including the following steps: Step 1, receiving the array to be sorted: obtaining the array data that needs to be sorted;
[0019] Step 2, selecting the pivot element: determining the first element of the array to be sorted as the only pivot element;
[0020] Step 3, element classification: traversing the other elements in the array except the pivot element, and classifying the elements into two sets according to the size relationship with the pivot element. The elements smaller than the pivot element are classified into the first set, and the elements greater than or equal to the pivot element are classified into the second set;
[0021] Step 4, recursive sorting: recursively executing the above sorting method on the first set and the second set respectively until the number of elements in the set is less than or equal to 1;
[0022] Step 5, result merging: combining the sorted first set, the pivot element, and the sorted second set in sequence to form the final ordered array.
[0023] In each round of recursive sorting operation, the first element of the current sub-array to be sorted is used as the pivot element for element classification.
[0024] In the element classification step, the comparison between an element and a reference element is a strict comparison. When the element is equal to the reference element, it is classified into a second set that is greater than or equal to the reference element.
[0025] During the recursive sorting process, the sorting logic called is consistent with the logic of the overall sorting method.
[0026] Specific implementation steps:
[0027] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
[0028]
[0029]
Claims
1. A sorting method, characterized in that: The following steps are involved: Step 1: Receive the array to be sorted: Get the array data to be sorted; Step 2, select the base element: determine the first element of the array to be sorted as the only base element; Step 3, element classification: traverse the elements in the array except the benchmark element, and divide the elements into two sets according to their size relationship with the benchmark element. Elements smaller than the benchmark element are classified into the first set, and elements greater than or equal to the benchmark element are classified into the second set. Step 4, recursive sorting: recursively execute the above sorting method on the first set and the second set respectively until the number of elements in the set is less than or equal to 1; Step 5: Merge the results: combine the sorted first set, the benchmark element, and the sorted second set in order into a final ordered array.
2. The sorting method according to claim 1, characterized in that: In each round of recursive sorting operation, the first element of the subarray to be sorted is used as the reference element for element classification.
3. The sorting method according to claim 1, characterized in that: In the element classification step, the comparison between the element and the reference element is a strict comparison. When the element is equal to the reference element, it is divided into a second set greater than or equal to the reference element.
4. The sorting method according to claim 1, characterized in that: In the recursive sorting process, the sorting logic called is consistent with the logic of the overall sorting method.