Commonly used sorting algorithms/programmers must master the 8-Big sorting algorithm

Source: Internet
Author: User
Tags sort

Classification:

1) Insert sort (direct insert sort, hill Sort)
2) Swap sort (bubble sort, quick sort)
3) Select sort (Direct select sort, heap sort)
4) Merge sort
5) Allocation sort (cardinal sort)

Maximum required auxiliary space: merge sort
Minimum required secondary space: heap Ordering
Fastest Speed: Fast sorting

Unstable: Quick sort, hill sort, heap sort.

Let's take a look at the relationship between the 8 sorts:


1. Direct Insert Sort

(1) Basic idea: In the set of numbers to be sorted, assume that the number of front (n-1) [n>=2] is already a row

In a good order, now you want to insert the nth number into the ordinal number in front, so that the n number

It's also in the right order. This cycle is repeated until all the rows are in order.

(2) Example

(3) Implementation in Java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Package Com.njue; Publicclass insertsort {public insertsort () {inta[]={49, 38, 65

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.