Sorting algorithms are widely used.
Typical applications:
- Sort name
- Sort MP3 music files
- Display Search Results of Google's web page ranking
- List RSS subscriptions in order of titles
After sorting, the following problems become very simple.
- Median)
- Identify abnormal values in statistical data
- Binary Search in the database
- Find duplicate emails in the mailbox
Not a typical application:
- Data Compression
- Computer Graphics
- Computing creature
- Load Balancing
Java System sorting (system sorts)
Arrays. Sort ().
- Different Methods correspond to different basic types.
- There is a method to implement the comparable Interface
- There is a way to use Comparator
- Use optimized quick sorting for basic types and optimized Merge Sorting for objects
The ordering of Java systems is not completely reliable.
Sorting Algorithm types:
Internal sorting:
Insert sorting, select sorting, Bubble sorting, and sieve sorting
Fast sorting, Merge Sorting, heap sorting, Hill sorting, and samplesort)
Card Sorting, red/Black sorting, open sorting, yaroslavskiy sorting, and P sorting
External sorting:
Multi-phase Merge Sorting, stacked merge, and oscillating sorting
String sorting:
Distributed sorting, MSD, LSD, and three-way fast sorting
Parallel sorting ::
Bitonic sorting and batcher parity sorting
Smooth sorting, cube sorting, and column sorting
GPU sorting
Which algorithm should I choose?
Select an algorithm as needed.
| |
In-situ sorting |
Stability |
Worst |
Average |
Best |
Remarks |
| Select sort |
Yes |
|
N^ 2/2 |
N^ 2/2 |
N^ 2/2 |
Minimum number of exchanges |
| Insert sort |
Yes |
Yes |
N^ 2/2 |
N^ 2/4 |
N |
Applicable to small arrays and partially sorted Arrays |
| Hill sorting |
Yes |
|
? |
? |
N |
Less code, complexity n ^ 1.5 |
| Merge Sorting |
|
Yes |
N lgn |
N lgn |
N lgn |
Stable complexity |
| Fast sorting |
Yes |
|
N^ 2/2 |
2n lnn |
N lgn |
Fastest speed in practical application |
| Three-way sorting |
Yes |
|
N^ 2/2 |
2n lnn |
N |
It is an improvement of normal quick rank. |
| ??? |
Yes |
Yes |
N lgn |
N lgn |
N lgn |
God Algorithm
|
Application System sorts for sorting algorithm part I week 3 in Princeton University algorithm Course