A summary of the seven major sorting methods of Classical Vernacular algorithms in eight morewindows

Source: Internet
Author: User

In my blogBubble sorting, direct insertion sorting, Direct selection of sorting, Hill sorting, Merge Sorting, fast sorting and heap sortingThese seven commonly used sorting methods are described in detail and made into e-books for you to download. Http://download.csdn.net/detail/morewindows/4443208.

Some netizens suggested that this book "seven major sorting of classical morewindows vernacular algorithms" be carefully used for daily study. However, there are 22 pages, which is not suitable for reviewing materials before the interview. So here we will summarize these seven common sorting methods so that you can better review these classic sorting algorithms and lay a good foundation for the interview.

 

First, review the main ideas of sorting:

I.Bubble Sorting

The main idea of Bubble Sorting is:

The two adjacent numbers are converted into decimal places after the first large number. After each traversal, the maximum number is "sunk" to the end. The array can be ordered by repeating n times.

Bubble sort Improvement 1: If there is no data exchange in a traversal, the entire array is ordered. Therefore, you can determine whether to continue the loop by setting a flag to record whether there is data exchange in this traversal.

Bubble Sorting Improvement 2: record the location where data exchange occurred at the end of a certain time. The data after this location is obviously sorted. Therefore, the range of the next loop can be determined by recording the location where data exchange finally occurs.

 

II.Insert sort directly

The main idea of direct insertion sorting is:

Each time you insert a data to be sorted to a sequence that has already been sorted until all data is inserted.

 

III.Select sort directly

The main idea of directly selecting sorting is:

The array is divided into ordered areas and unordered areas. At first, the entire array is unordered. Then, each time you select the smallest element from the unordered area, it is directly placed at the end of the ordered area until the entire array becomes ordered.

The above three sorting types are very simple, and the following four sorting types are slightly difficult. I hope readers can practice them more to deepen their understanding.

 

4.Hill sorting

The main idea of hill sorting is:

First, the entire sequence of elements to be arranged is divided into several sub-sequences (composed of elements separated by an increment) for direct insertion and sorting, and then the incremental sequence is reduced and then sorted, when the elements in the entire sequence are basically ordered (the increment is small enough), directly insert and sort all the elements. Because the hill sorting is onSeveral distancesData.Insert sort directlyTherefore, the image can be called "Hill"Jumper"

 

5.Merge Sorting

The main idea of Merge Sorting is:

When an array is ordered on the left and on the right, merge the two arrays to complete the sorting. How to make the left and right sides orderly? Recursion! This wayRecursion and mergingMerge Sorting.

 

6.Quick sorting

The main idea of quick selection and sorting is:

"Number of digging holes + division and Control Measures"First, make I = L; j = r; dig out a [I] to form the first pitfall, which is called a [I] as the reference number. Then j -- From the back to find a smaller number than the benchmark, and then dig out this number and fill in the previous pit a [I, then I ++ finds a number larger than the reference number from the front to the back, and then mines this number to fill in the previous pit a [J. Repeat this "Number of traps" until I = J. Then fill in the reference number in a [I], so that the number before I is smaller than the reference number, and the number after I is larger than the reference number. Therefore, the array is divided into two parts and then the preceding steps are repeated to complete the sorting.

 

7.Heap sorting

The main idea of heap sorting is better shown in the figure below:


It can be seen that the difficulty of heap sorting lies in the insertion and deletion of heap.

Heap insertion is -- each insertion puts the new data at the end of the array, and from the parent node of the new data to the root node must be an ordered series, therefore, you only need to insert the new data into the ordered sequence.

Heap deletion is -- heap deletion is to assign the value of the last data to the root node, and then make a top-down adjustment from the root node. When adjusting, first find the smallest node in the left and right son node. If the parent node is smaller than the smallest child node, it does not need to be adjusted. Otherwise, switch the parent node with it before considering the subsequent node. It is equivalent to "Sinking" A data from the root node in an ordered series ".

Therefore, heap insertion and deletion are very similar.Insert sort directly, Not inBinary Tree. So we can describe the heap sorting as"Tree Insertion"

 

 

Use a chart to show the relationships between the seven common sorting methods.

 

 

Well, the seven common sorting methods are summarized here. I believe you will be impressed by writing the code on the machine and looking at this figure again. You can print the last figure when preparing the interview materials so that you can quickly review the materials before the interview. I wish you a smooth interview and a satisfactory offer.

 

The new version of the book "morewindows vernacular classical algorithm of the seven sort 2nd version (HD)" has been uploaded successfully, is: http://download.csdn.net/detail/morewindows/4560056

 

Reprinted please indicate the source, original address: http://blog.csdn.net/morewindows/article/details/7961256

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.