Class notes: basic concepts of sorting

Sorting : Given a set of records {r1, r2,…, rn}, the corresponding key codes are {k1, k2,…, kn}, and sorting is to arrange these records in the order {rs1, A sequence of rs2, ......, rsn}, so that the corresponding key code satisfies ks1≤ks2≤ ... ≤ksn (called ascending order) or ks1≥ks2≥ ... ≥ksn (called descending order).
Positive sequence : The records in the sequence to be sorted have been sorted by key code.
Reverse order (reverse order) : The order of the records in the sequence to be sorted is the reverse of the sorted order.
Trip : In the sorting process, scanning the sequence of records to be sorted is called a trip. Usually, a sorting process requires multiple scans to complete
the stability of the sorting algorithm : Suppose there are multiple records with the same key value in the record set to be sorted. If sorted, the relative order of these records remains unchanged, That is, in the original sequence, ki = kj and ri is before rj, and in the sorted sequence, ri is still before rj, this sorting algorithm is said to be stable; otherwise it is called unstable.
For an unstable sorting algorithm, just give an example to explain its instability; and for a stable sorting algorithm, the algorithm must be analyzed to prove the stable characteristics.
It should be noted that whether the sorting algorithm is stable is determined by the specific algorithm. An unstable algorithm can become a stable algorithm under certain conditions, and a stable algorithm can also become an unstable algorithm under certain conditions.
The stability of the algorithm is related to the specific implementation of the algorithm.
Bubble sorting is a stable sorting method.
5, 3, 3, 4
If the rule is A [i]> a [i + 1], it is stable, if the rule is A [i ]> = a [i + 1], is an unstable sorting method.
Quick sorting was originally an unstable sorting method, but if there is only one set of records with the same key code in the record to be sorted, and the selected axis value happens to be one of the same key code, the quick sorting at this time is stable .
Sorting classification-according to whether the sorted data is in memory or in external storage :
1. Internal sorting : All records to be sorted are placed in memory during the entire sorting process
2. External sorting : due to the number of records to be sorted There are too many to be placed in the memory at the same time, and some records need to be placed in the memory, and another part of the records are placed in the external memory. The entire sorting process requires multiple data exchanges between the internal and external memory to obtain the sorting result.
Sorting sorting-According to the basic operations performed during the sorting process :
1. Based on comparison : basic operation-comparison of key codes and movement of records, the worst time limit has been proved to be O (nlog2n).
2. Not based on comparison : According to the distribution characteristics of key codes. For example, bucket sorting, cardinality sorting (multi-key sorting)
based on the comparison of internal sorting :
1, insertion sorting 2, exchange sorting 3, selection sorting 4, merge sorting is
not based on the comparison of internal sorting :
1, allocation sorting 2, buckets Sorting 3.
Performance of radix sorting algorithm
1. Time complexity: basic operation .
The basic operation of internal sorting in the sorting process:
comparison : comparison between key codes;
⑵Movement : The record moves from one location to another location.
2. Space complexity: Auxiliary storage space .
Auxiliary storage space refers to the storage space required to execute the algorithm in addition to the storage space occupied by the records to be sorted under the condition of a certain data size.
Storage structure of sorting algorithm
From an operational point of view, sorting is an operation of linear structure, and the records to be sorted can be stored in a sequential storage structure or a linked storage structure.

Published 48 original articles · Like 25 · Visit 2453

Guess you like

Origin blog.csdn.net/qq_43628959/article/details/104362946