Performance Analysis of sorting algorithms

Source: Internet
Author: User

I. Comparison-based sorting algorithms

1. Insert sorting method

Direct insertion sorting, Hill sorting, not commonly used: Tree sort; Library sort: Patience sorting

2. Exchange sorting

Bubble sorting, fast sorting, not commonly used: Cocktail sorting, parity sorting

3. Select sort

Directly select sorting and heap sorting

4. Merge Sorting

Merge Sorting

Ii. Comparison-based sorting algorithms

Base sorting and bucket sorting

3. Space, time complexity, and stability

.

2. O (nlogn) Performance Analysis

The average performance of O (nlogn) is :. Among them, fast sorting is the best, followed by merging and Hill. The effect of heap sorting is obvious when the data volume is large.

The four sorting types can be viewed as "advanced algorithms". However, when the columns to be sorted are sorted in basic order, they will become Bubble sorting, which is close to O (n ^ 2 ).

Hill sorting has no satisfactory answer to the increment standard, and the increment has an impact on the performance.

Merge Sorting is very efficient.

Most advanced algorithms are compared by leaps and bounds, reducing the number of comparisons, But sacrificing the stability of sorting.

3. Insert sorting, Bubble sorting, binary tree sorting, and Merge Sorting are all stable.

 Is unstable.

Iv. Sorting Algorithm Selection

1. Small Data size

(1) When the basic order of the columns to be sorted is selected, you can insert the sorting directly.;

(2) Not applicable to stability requirements, but applicable to stability requirements

2. The data size is not large.

(1) memory space is fully available, and the sequence is messy and unordered. There is no requirement for stability and fast sorting.In this case, additional space for log (N) is required.

(2) The sequence itself may be ordered and requires stability. It is suitable for use when space permits.

3. Massive Data must be stored on external storage by block

(1) consider stability.

(2) No requirements for stability, applicable

Random fast sorting

5. Overall analysis of various sorting algorithms

Bubble sorting, insert sorting, Hill sorting, and quick sorting are sensitive to Data ordering., Especially Bubble sorting and insert sorting;

 The sorting time in its worst case is not much different from its best case. The number of comparisons is n (n-1)/2, but selecting sorting can move elements very effectively. Therefore, for tables with almost the correct order, the selection of sorting may be much slower than the insertion of sorting.

In the optimal case, the Bubble sorting result can be obtained after N-1 comparisons (I .e., for tables in full positive order). In the worst case, the results must be compared n (n-1)/2 times, the number of comparisons selected for sorting is the same, but the number of data exchanges is redundant because the Top N-1 is selected for sorting, data exchange n (n-1)/2 in the worst case of Bubble sorting. Bubble Sorting does not have to be conducted. However, because of its large number of records moving, its average time performance is worse than insertion sorting.

Insert sorting has a minimum number of comparisons in the best cases, but it is very inefficient in Moving Elements because it only compares with adjacent elements and is less efficient.

Hill sorting is actually the insert sorting after optimization in the pre-processing phase. Generally, when it is large ,.

The quick sorting uses the idea of "small, small" and uses recursive methods to resolve the original problem into subproblems that are small but similar to the original problem. The average time complexity of the fast algorithm is O (nlogn), on average, but because the fast sorting adopts the recursive method. Quick Algorithms are especially suitable for sorting random sequences.

 

Bubble sorting, insert sorting, select sorting, Hill sorting, and quick sorting.However, the order of advantages and disadvantages is not absolute. In different cases, a full performance reversal may even occur.

The initial status has a positive order., SuchInsert sorting, Bubble sorting, and select sortingAnd other methods

Quick sorting method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.