Sorting Algorithm summary, Sorting Algorithm

Source: Internet
Author: User

Sorting Algorithm summary, Sorting Algorithm
Note:




Insert sort: 1: insert sort O directly (n ^ 2)
2: semi-inserted sorting O (n ^ 2)
3: Hill sorting O (n multiplied by the log base 2, the logarithm of n)
Space complexity is O (1)


Exchange sort: 1: bubble sort O (n ^ 2), space complexity O (1)
2: Fast sorting of O (n multiplied by the log base 2, the logarithm of n), space complexity O (log base 2, the logarithm of n)


Select class sorting: 1: Simple selection of sorting O (n ^ 2), Space O (1)
2: heap sorting O (n multiplied by the log base 2, the logarithm of n), space complexity O (1)


Two-way Merge Sorting: O (n multiplied by the log base 2, the logarithm of n), space complexity O (n)


Base sorting: time O (d (n + rd) d: Number of keywords, n: number of elements, rd: value range of keywords
Space O (rd)
Note: For value sorting, the base sorting can only be performed from low to high, and can be ordered, (high to low, no)










1: on average, (fast, Greek, returning, heap)-> time complexity O (n multiplied by the log base by 2, the logarithm of n)

Other O (n ^ 2), base sort O (d (n + rd) d: Number of keywords, n: number of elements, rd: value range of keywords


2: spatial complexity, fast-> O (log base 2, logarithm of n)
-> O (n)
Base-> O (rd)

Others-> O (1)


3: time complexity. Direct insertion and bubbling are easy (ordered) to change to O (n)


4: unstable sorting-> (fast, Greek, select, heap)


5: after sorting, an element can reach the final position: a switching class (bubble, fast)

B. Select a class (select, heap)


6: sorting. The number of element comparisons is irrelevant to the original sequence. a selects sorting.
B-semi-insert sorting

In addition, the time complexity (merging, heap, and base) is irrelevant to the start time.


7: The number of sorted orders (all numbers are processed once for one trip) is related to the original sequence ---> exchange class: Run/fast









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.