2014 soft test programmer-frequent test knowledge point review notes [Chapter 5]

Source: Internet
Author: User
Tags sorts

51cto college specially sorted out "2014 soft test programmer-General test knowledge point review notes [summary]" in the soft test preparation season to help schools pass through smoothly! For more software proficiency test counseling and questions, please pay attention to the 51cto college-soft exam classification!


View summary:2014 soft test programmer-frequent test knowledge point review notes [summary]650) This. width = 650; "alt =" popular article "src =" http://www.exam8.com/images/hot.gif "style =" padding: 0px; margin: 0px; Vertical-align: middle; Border: 0px; "/>


Internal sorting

Measure the test taker's knowledge about the sorting algorithms and their ideas in books, as well as their advantages and disadvantages and performance indicators (time complexity.

There are five sorting methods: insert, select, exchange, merge, and count.

(1) insertion sorting can be further divided into: Direct insertion, semi-insertion, and two-way insertion (?) And Hill sorting. The most fundamental difference between these sort insertion algorithms is to find new element insertion points based on the rules. Direct insertion is sequential search, semi-insertion is semi-search, and Hill sorting, it is to improve the sorting efficiency by controlling the increment of the total number of involved orders from small to large.

(2) Exchange sorting, also known as Bubble sorting, can be improved and quickly sorted based on exchange sorting. The idea of fast sorting is one word: Split the Data Group to be sorted into two parts by using the intermediate number.

(3) Selection and sorting can be divided into simple selection, tree selection, and heap sorting. Compared with the preceding sorting algorithms, sorting is more difficult. The difference between the three methods is that the minimum number is selected based on the Rule.

A simple choice is to determine the minimum number through a simple array traversal scheme;

Tree selection is based on the idea similar to the "championship", so that the smaller (smaller) players are eliminated and the smallest (larger) number is finally selected;

Heap sorting uses the data structure of heap to select and place the minimum number on the top of heap through a series of operations such as deleting and adjusting heap elements. Heap establishment and heap adjustment in heap sorting are important test points.

(4) Merge Sorting is achieved through the "merge" operation. Since it is a merge, it is possible to merge data sets that are more than two. Therefore, in the Merge Sorting, the most important thing is the two merge. The algorithm is relatively simple. Remember that Merge Sorting is a stable sorting.

(5) Base sorting is a special sorting method. It is precisely because of its special nature that base sorting is more suitable for some special occasions, such as playing card sorting. There are two types of base sorting: Multi-Keyword sorting (playing card sorting) and chain sorting (integer sorting ). The core idea of base sorting is to use the concept of "base space" to standardize and reduce the scale of the problem. In addition, in the process of sorting, as long as you follow the idea of base sorting, there is no need to compare keywords. the final sequence obtained in this way is an ordered sequence.

The ideas of various sorting algorithms and pseudo-code implementation in this chapter, as well as their time complexity, must be mastered.

Stability Analysis

In general, the stability of the sorting algorithm is to ensure that the first two equal numbers are in the same order before and after the sequence and the former two are in the same order.

Stability benefits: If the Sorting Algorithm is stable, it sorts data from one key and then from another key, the result of sorting by the first key can be used by sorting by the second key. In this case, the base sorting is performed first by the low position, and then by the high position. The order of the elements with the same low position and the high position will not change at the same time. In addition, if the Sorting Algorithm is stable, for comparison-based sorting algorithms, the number of element exchanges may be less (personally, not confirmed ).

Analyze the stability of common sorting algorithms, and each gives a simple reason.

(1) Bubble Sorting

Bubble Sorting is to call a small element forward or a large element backward. The comparison is an adjacent comparison between two elements, and the Exchange also occurs between these two elements. Therefore, if the two elements are equal, I think you will not be bored to exchange them. If the two equal elements are not adjacent, even if the two are adjacent through the previous two exchanges, at this time, the sequence of the same elements is not changed, so the Bubble Sorting is a stable sorting algorithm.

(2) Select sorting

The sorting mode selects the smallest element for each position. For example, you can specify the smallest element for the first position, select the second smallest element for the second element in the remaining element, and so on, the n-th element does not need to be selected until the n-th element, because only one of its largest elements is left. If the current element is smaller than an element, and the small element appears after an element equal to the current element, then the stability will be damaged after the exchange. Compare interfaces. For example, in the sequence 5 8 5 2 9, we know that the first selection of 1st elements 5 will exchange with 2, therefore, the relative order of the two 5 in the original sequence is damaged. Therefore, selecting sorting is not a stable sorting algorithm.

(3) Insert sorting

Insert sorting inserts an element at a time based on an ordered small sequence. Of course, at the beginning, this ordered small sequence had only one element, which was the first element. The comparison starts from the end of the ordered sequence, that is, the element to be inserted is compared with the already ordered sequence. If it is larger than it, it is directly inserted after it, otherwise, search until you find the inserted position. If you encounter an element that is equal to the inserted element, the inserted element is placed behind the element that you want to insert. Therefore, the order of equal elements is not changed, and the order from the original unordered sequence is the order after sorting, so insertion sorting is stable.

(4) Fast sorting

There are two directions for quick sorting. The I subscript on the left is always directed to the right. When a [I] <= A [center_index], center_index is the array subscript of the central element, it is generally set to an array of 0th elements. The J subscript on the right goes to the left, when a [J]> A [center_index]. If I and j cannot move, I <= J, exchange a [I] And a [J], repeat the above process until I> J. Exchange a [J] And a [center_index] to complete a quick sorting. When the central element is exchanged with a [J], it is very likely to disrupt the stability of the preceding elements. For example, the sequence is 5 3 3 4 3 8 9 10 11, now the exchange of central elements 5 and 3 (5th elements, subscript starting from 1) will disrupt the stability of element 3, so fast sorting is an unstable sorting algorithm, instability occurs when the central element is exchanged with a [J.

(5) Merge and sort

Merge Sorting refers to recursively dividing a sequence into short sequences. The recursive exit means that a short sequence has only one element (that is, directly ordered) or two sequences (one comparison and exchange ), then, the ordered segments are merged into an ordered long sequence until all the original sequences are sorted. It can be found that when one or two elements, one element will not be exchanged. If two elements are equal in size, no one will intentionally exchange them, which will not damage stability. So, in the process of merging short ordered sequences, is stability damaged? No. During the merge process, we can ensure that if the two current elements are equal, we store the elements in the previous sequence before the result sequence, thus ensuring stability. Therefore, Merge Sorting is also a stable sorting algorithm.

(6) Base sorting

Base sorting is sorted first by low position, then collected; then sorted by high level, and then collected; and so on until the highest bit. Sometimes some attributes have a priority order. They are first sorted by low priority and then by high priority. The final order is the highest priority, and the highest priority is the highest priority. Base sorting is based on separate sorting and collected separately, so it is a stable sorting algorithm.

(7) Shell)

Hill sorting sorts elements by insertion of different step sizes. When the elements are unordered at the beginning, the step size is the largest, so the number of elements inserted for sorting is very small and the speed is very fast; when the elements are basically ordered, the step size is very small, and insertion sorting is very efficient for ordered sequences. Therefore, the time complexity of hill sorting is better than that of O (N ^ 2. Because of the multiple insertion sorting, we know that one insertion sorting is stable and does not change the relative order of the same elements. However, in different insertion sorting processes, the same elements may move in their respective insert sorting, and the final stability will be disrupted, so shell sorting is unstable.

(8) Heap sorting

We know that the heap structure is that node I has 2 * I and 2 * I + 1 nodes, and the parent node must be greater than or equal to its 2 child nodes, the child top heap requires that the parent node be smaller than or equal to its two child nodes. In a sequence with a length of N, the heap sorting process starts from n/2 and selects the maximum value (large top heap) or the minimum value (small top heap) for its subnodes ), of course, the choice between these three elements will not undermine stability. However, when selecting elements for the n/2-1, n/2-2,... 1 parent nodes, the stability will be damaged. It is possible that the nth/2nd parent node swaps the next element, while the nth/2-1 parent node does not swap the next element, then the stability between the two identical elements is damaged. Therefore, heap sorting is not a stable sorting algorithm.



Recommended high-quality articles:

Preparing for the 2014 soft exam! Recommendation of high-quality video tutorials (Comprehensive review + experience sharing + pre-test Sprint)

Knowledge points of Network Management in 2014 computer soft examination [summary]

Exercise questions and answers for the 2014 soft exam Network Administrator examination [summary]

2014 soft test programmer-test-exercise questions before the test [summary]


For online soft test video tutorials, click:

Http://edu.51cto.com/course/courseList/id-44.html



650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3D/9F/wKioL1PE_n3z629yAACXIHScsJM092.jpg "alt =" wkiol1pe_n3z629yaacxihscsjm092.jpg "style =" padding: 0px; margin: 0px; Vertical-align: Top; Border: none; "/>


This article is from the "51cto college official blog" blog, please be sure to keep this source http://51edu.blog.51cto.com/8899635/1539372

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.