Basics of basic sorting
- If a basic sorting algorithm is not more slow than data processing, such as reading and reading, there is no need to find a faster algorithm.
- If the sorted file fits in memory, the sort method is called an internal sort , and sorting the files from disk is called an external sort . The difference is that an internal sort can easily access any element, but an external sort must sequentially access the element, at least in large chunks.
- how the ordering program accesses elements : By comparing the keywords, directly accessing the entire element movement;
- Sort functions have 3 parameters: arrays, left and right borders with sorted word groups
void(Item a[], int l, int r);
- run time of the sorting algorithm: When ordering n elements
- Select Sort, insert sort, bubble sort, and < Span class= "Mrow" id= "mathjax-span-2" > n 2 proportional;
- Hill sort (improvement of insertion sort) is proportional to N (3/2);
- Keyword-index ordering is proportional to N;
- how to reduce overhead and speed up sorting : (important)
- Switch to a more efficient algorithm
- Shorten the internal cycle
- Check if there is a comparison or swap operation that can be skipped
Basic sorting algorithm type 1. Select sort
Select the smallest element in the array, swap it with the first element in the array, and then find the minor element and swap it with the second element in the array ... Until the entire array sort is complete. That is, by constantly selecting the smallest element in the remaining array to implement.
2. Insert Sort
By constructing an ordered sequence, for unsorted data, a backward-forward scan in a sorted sequence to find the appropriate location to insert. Thus, in the process of backward forward scanning, the ordered elements need to be shifted back and forth gradually, providing the insertion space for the newest elements.
3. Bubble sort
Traverse the file, if the next 2 elements are in the wrong order, swap the two and repeat until the sort is complete
4. Hill sort 5. Index and pointer ordering
Summary of basic sorting algorithm