My soft test path (6) -- eight sorting of data structures and algorithms (4)

Source: Internet
Author: User

Sorting is the foundation of programming. It is often used in programs. A good sorting method can help you improve the efficiency of program execution. Therefore, you can learn sorting well and lay a good foundation for program optimization. No matter how powerful your technology is, it's impossible to assume you have no foundation.

Let's just move on to today's topic.


Some people say that sorting is very difficult, but I always think it is very easy. We just need to understand the basic idea and use a simple example to deepen our understanding.


1. Insert directly to sort


(1) Brief Introduction: insert the sorting directly. It can be seen from the literal meaning that the data is directly inserted into the sorting.

(2) Basic Idea: when inserting the number of I, if the number of I-1 has been sorted, just need to insert the number of I into the I-1, so that the number of I is also sequential.

(3) For example:



2. Shell sorting)


(1) A Brief Introduction: Hill sorting, also known as downgrading incremental sorting, is an improvement to the direct insertion sorting method.

(2) Basic Idea: divide the whole sequence into multiple sub-sequences, and then sort them directly by insert until all the numbers in the sequence are basically ordered, and then sort the total directly by insert.

(3) For example:


3. Simple selection and sorting


(1) Brief Introduction: simply selecting sorting is also called directly selecting sorting. In fact, simply inserting sorting is very simple and inefficient.

(2) Basic Idea: first select a minimum number from N and delete it from it as the first number of a new group. Then, select the minimum number from the remaining number, delete it from it as the second number of the new group .... Repeat this until the sorting is complete, and finally get a set of numbers sorted from small to large.

(3) For example:


4. Heap sorting


(1) Brief Introduction: heap sorting is a very practical sorting technology, especially suitable for sorting a large number of records. At the same time, heap sorting also improves the simple selection and sorting.

Stack definition: The sequence of n elements {K1, K2 ,..., kN} when the following relationship is met, it is called heap: Ki ≤ k2i and Ki ≤ k2i + 1 or ki ≥ k2i and Ki ≥ k2i + 1. Note: The heap tree must be a Complete Binary Tree.

(2) Basic Idea: using the data structure such as the stacked tree to design a sort, can use the characteristics of the array to quickly locate the elements of the specified index.

Max heap: the parent node is greater than or equal to the son Node

Minimum heap: the parent node is less than or equal to the child node

(3) For example:

Adjust the sequence {20, 60, 26, 30, 36, 10} to the ascending sequence.

1. First, create a Complete Binary Tree for the data. The fill rule is to fill in the data one by one based on hierarchical traversal, and finally build the minimum heap;


2. Extract the heap top and adjust the elements after deleting the Team Top as the new heap;

3. Repeat Step 1 until the heap is empty;


4. The heap top is sorted in ascending order.


5. Bubble Sorting


(1) Brief Introduction: Bubble Sorting is the same as the objects in the water. Small objects move up and down, while large objects sink down.

(2) Basic Idea: vertically arrange the array and retrieve the last element one by one and exchange it up to obtain a large number (decimal number). Continue to Step 1 until the sorting is complete.

(3) For example:


6. High-speed sorting


(1) Brief Introduction: high-speed sorting is the fastest Sorting Algorithm in internal sorting.

(2) Basic Idea: select a data (usually the first number of arrays) as the important data, and put all the numbers smaller than it in front of it, all the numbers greater than it are placed behind it. This process is called a high-speed sorting. Then, we select the benchmark number from the separated parts, divide the groups, and run them repeatedly until they are completed.

(3) For example:


7. Merge and sort


(1) A Brief Introduction: Merge Sorting is also called a two-way merge operation. The merge operation completes the sorting algorithm.

(2) Basic Idea: combine two or more ordered tables into a new ordered table, and finally combine all the ordered tables into an overall ordered table.

(3) For example:


8. Base sorting


(1) Brief Introduction: the sorting methods described above are all for elements, and the base sorting is for tuples.

(2) Basic Idea: from low to high, sort the numbers in order for distribution and collection. After D-train allocation and collection, an ordered sequence can be obtained.

(3) For example:



Sorting Algorithm comparison


Summary

People have the strongest ability to process images. I believe you have learned these eight types of sorting through this image.



Welcome to the blog update list.

My soft test path (1) -- opening (updated)

My soft test path (2) -- j2se macro Summary (updated)

My soft test path (iii) -- linear table of Data Structure and algorithm (1) (updated)

My soft test path (4) -- Data Structure and algorithm (2) tree and binary tree (updated)

My soft test path (5)-data structure and algorithm (3) diagram (updated)

My soft test path (6) -- eight sorting of data structures and algorithms (4) (updated)

My soft test path (7)-data structure and algorithm (5) Search (updated)


My soft test path (6) -- eight sorting of data structures and algorithms (4)

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.