Classical algorithm (8) Morewindows of the vernacular classical algorithm of the seven major ranking summary

Source: Internet
Author: User

In my blog for bubble sort, direct insertion sort, direct selection sort, hill sort, merge sort, quick sort and heap sort seven common methods of sorting are explained in detail and made into an electronic book for everyone to download. The download address is: http://download.csdn.net/detail/morewindows/4443208.

Some netizens proposed to this "morewindows vernacular classical algorithm seven big sort" electronic book explanation meticulous uses in peacetime study is very good, but the page has 22 pages, is not suitable to do before the interview review material. So here will these seven kinds of commonly used sorting methods to summarize, so that we better review these classic sorting algorithm, for the interview lay a good foundation.

First of all, review the main ideas of the sorting:

A Bubble sort

Bubble sort the main idea is:

By swapping, the number of adjacent two digits is changed to a decimal number, so that after each traversal, the maximum numbers are "sunk" to the last level. Repeat n times to make the array orderly.

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

Bubble sort Improvement 2: Record the last occurrence of the data exchange at the end of the time, the data after this position is clearly in order. So you can determine the scope of the next cycle by recording the location of the last data exchange.

Two Direct Insert Sort

The main ideas for direct insertion sequencing are:

Each time one of the data to be sorted is inserted into the sequence of the preceding order until all the data is inserted.

Three Direct Selection Sort

The main ideas of direct selection sequencing are:

The array is divided into ordered and unordered regions, and the whole array is unordered at the initial time, and then each time the smallest element is selected from the disordered region to the end of the ordered region, until the whole array is ordered.

The above three kinds of sorting are very simple, the following four kinds of sorting is slightly difficult, hope that the reader can practice more to deepen understanding.

Four Hill sort

The main ideas of hill-sorting are:

The entire backlog sequence is divided into several sequences (consisting of an element separated by an "increment") for direct insertion, respectively. Then the increment is then sorted, and the elements in the whole sequence are basically ordered (the increment is small enough), and then the whole element is inserted in a direct order. Since hill sorting is a direct insertion of data at several distances apart, it is possible to call Hill sort as "jumping plug"

Five Merge sort

The main ideas of merging sort are:

When an array is left orderly and the right is ordered, merging the two ordered arrays completes the order. How to make the left and right sides orderly? Use recursion! This recursion goes on, merging up is the merge sort.

Six Quick Sort

The main ideas for quick choice sorting are:

"Digging pit filling number + Divide the method", first make I =l; j = R; The a[i] is dug up to form the first pit, which is called A[i] as the base number. Then j--from the back of the number of smaller than the base number, found after digging this number into the previous pit a[i], and then i++ from the front backward looking for the number of large base number, found also dug this number to fill in the previous pit a[j]. Repeat this "pit fill" until i==j. Then fill in the base number in a[i], so that the number before I is smaller than the base number, I after the number is larger than the benchmark number. Therefore, dividing the array into two parts and repeating the above steps separately completes the order.

Seven Heap Sort

The main idea of heap sorting is to use a diagram to indicate better:

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.