A common sort algorithm and corresponding time complexity and space complexity of __ sorting algorithm

Source: Internet
Author: User

Reprint please indicate the source:

http://blog.csdn.net/gane_cheng/article/details/52652705

Http://www.ganecheng.tech/blog/52652705.html (better browsing effect)

The sorting algorithm has evolved over a long period of time, resulting in a number of different methods. For beginners, it is important to organize them to facilitate the understanding of memory. Each algorithm has its own specific use situation, it is difficult to general. Therefore, it is necessary for us to generalize all the common sorting algorithms.

Sorting large categories can be divided into two types: inner and outer sort. In the sort process, all records are stored in memory, which is called the inner sort, and if you need to use external storage in the sorting process, it is called the outer sort. The sort that follows is all about the inner sort.

The inner sort can be divided into the following categories:

(1), insert sort: direct insertion sort, binary insertion sort, hill sort.

(2), select Sort: Direct select sorting, heap sort.

(3), Exchange sort: bubble sort, quick sort.

(4), merge sort

(5), Cardinal Order

form Version

Sorting Method complexity of Time (average) complexity of Time (worst) Complexity of Time (best) Complexity of Space Stability Complexity
Insert sort directly O (n2) O (n^2) o (n2) O (n^2) o (n) o (n) O (1) o (1) stable simple
Hill sort o (nlog2n) O (nlog_{2}n) o (n2) o (n^2) o (n) o (n) o (1) O (1) unstable more complex
Select sort directly O (n2) O (n^2) o (n2) O (n^2) o (n2) O (n^2) O (1) O (1) unstable simple
heap sort o (nlog2n) O (nlog_{2}n) o (nlog2n) O (n log_{2}n) o (nlog2n) O (nlog_{2}n) O (1) O (1) unstable more complex
Bubble Sort O (n2) O (n^2) O (n2)

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.