Comparison of various sorting algorithms (best, worst, average time complexity, spatial complexity, stability)

Source: Internet
Author: User
Tags comparison table

Comparison table

Classification Algorithm Complexity of Time Complexity of space Stability Relevance of
Best Worst Average
Insert Sort Direct Insert Sort O (n) (after optimization) O (N2) O (N2) O (1) Stability
Hill sort O (N) O (N2) Not sure O (1) Not stable Sort based on direct insertion
Select sort Direct Select sort O (N2) O (N2) O (N2) O (1) Not stable
Heap Sort O (NLOGN) O (NLOGN) O (NLOGN)

Sort in place-O (1)

Not stable Application of the concept of selection
Exchange sort Bubble sort O (n) (after optimization) O (N2) O (N2) O (1) Stability
Quick Sort O (NLOGN) O (N2) O (NLOGN)

Preferably O (Logn),

Worst O (n)

Not stable Based on bubble sort
Merge sort O (NLOGN) O (NLOGN) O (NLOGN) O (N) Stability
Base sort

O (d* (n+r))

D is the number of digits, R is the cardinality,

n is the number of comparisons

O (d* (n+r)) O (d* (n+r)) O (N+r) Stability

Comparison of various sorting algorithms (best, worst, average time complexity, spatial complexity, stability)

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.