Hidden sorting algorithms

Source: Internet
Author: User

Hidden sorting algorithms

Sorting Algorithm. In the past, when Mr. Rice talked about VB, he talked about sorting. The Sorting Algorithm randomly showed 10 numbers and the maximum number. The sort algorithms such as bubble and Hill have all said that this introduction to data institutions once again met, and the soft test once again, it should be relatively easy.

After learning about data structure, I learned more about sorting algorithms. We all know that sorting is a kind of operation of data processing. Because it takes a lot of time to process data, we have proposed a variety of sorting algorithms to improve the running efficiency of computers.

In the words of Mr. Mi, it is "two-two comparison exchanges ".

Compare the size of two keywords and move the record from one location to another.

Stability of sorting:

Judge the stability, and determine the relative position changes before and after sorting by two records with the same key value.

For example, a group of data has been known: 1, 3, 2, 5, 6,2

Obtain 1, 2, and,22 With underlines before sorting 3, 5, and 6 is behind 2 without underlines, And the sorting order is still behind it. Otherwise, it is unstable.


1. Insert sorting

 

Insert sort directly: Insert each record to an ordered table with a sorted order to obtain a new ordered table with a 1 Increase in the number of recorders.

Personal Understanding: compare it with the ordered table data, and place it in the appropriate position until the sorting is complete. Direct insert sorting is a sort that is less than the number of records.

 

2. Exchange sorting (for comparison between two key values, if the two key values are in reverse order, they are exchanged .)

 

Bubble Sorting: Compare the key value of the first record with the key value of the second record. If it is in reverse order, it is exchanged. Then, compare the key values of the second record and the third record, n-1 and nth.

Personal Understanding: Compare the last number with the previous one to see if it is required to be exchanged.

 

Quick sorting:Take the key value of one record as the standard among n records. Sort the records to be sorted in a single order and divide them into independent parts smaller than, equal to, and greater than the key value, then proceed to the quick sorting.

The first round of sorting is relatively difficult (for external users). This will be simple in the future. A sort step: point the two pointers I and j to the initial position and the last position respectively, and then perform the following two steps:

(1) j gradually decreases, and the size of the elements pointed to by j and the target element is successively compared. If p (j) <T, the position is switched.

(2) Gradually increase I and compare the size of the elements to which I points. If p (I)> T, the position is switched.

 

3. Select sorting

Select sort directly: In the I selection operation, the records with the smallest key value are selected from n-I + 1 through the key-Value Comparison of n-I, and I (1 <= I <= N-1) records.

My understanding: Find the smallest number and exchange it with the previous one.

 

Heap sorting:

First, you must know that heap sorting is a kind of tree-based sorting. Building an initial sequence into a heap is a process of repeated filtering.

My personal understanding: the process of adjusting from top to bottom to rebuilding the heap.

4. Merge and sort

Combine two or more ordered tables into a new ordered table.

Two-way Merge Sorting

Is the sorting method that combines two ordered tables into one ordered table.

My understanding: 1. merge two adjacent records, compare and sort each other

2. merge the two and then compare them for sorting.

Conclusion: A sentence is "two-two comparison exchanges !"

The above learning method is very bad. Although we have understood each sort, we have not compared it and have not compiled the knowledge network. Each sort may have similarities and differences, the process may be confused.

Learning Method: Based on what the previous teacher said, the old knowledge is used to review and simplify it.

Problems:

Because they do not compare each sort, and each sort has some similarities, all will be confused.

Insert sort VS bubble sort:Insert sorting starts from the second key value and compares it with the previous number to a proper position;

Bubble Sorting compares the key values of 1 and 2, and compares the key values of 2 and 3 ...... The key values of n and n-1 are compared. If the reverse order is displayed, the values are exchanged.

Bubble sort VS direct sorting:

The Bubble Sorting is a triangle, and the direct sorting is a Left triangle.

During the entire sorting process, the Bubble sorting process can be performed at most n-1 bits. Directly select the sorting method for n-1 comparison, and find the smallest (largest) key value for each batch to exchange with the previous one.

In this way, you will not be confused easily. My personal understanding may have problems. I hope you can point out, thank you.




Which of the following is an idiom?

The shadows

There is a song, And the lyrics can't be avoided. It seems that there is another one that you used to sing to my good girl, with a fast pace.

Did you say "no"
 

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.