First, prefaceIn the previous article we have a summary of all the sorting algorithm, the following small series and to share with you the choice of sorting algorithm.Ii. Core points of knowledgeThe core idea of choosing sort is that I am the biggest .Select Sort (Selection sort) is a simple and intuitive sorting algorithm. Regardless of the language of the textb
] = arr[j+1];ARR[J+1] = temp;}}}}}Of course, Java can also be quick to sort, but it is recommended that you do not write fast sorting, because Java provides a lot of class library, the direct call on the line to save a lot of writing code necessary. For the sort method, call
unordered area to the heap (also known as the Rebuild heap).Attention:① Just do n-1, choose a larger n-1 keyword that can make the file increment order.② with small Gan is similar to the use of large root heap, except that its ordering result is descending order. Heap sorting and direct selection ordering is the opposite: at any time the unordered region in the heap sort is always before the ordered region, and the ordered region is gradually extende
number of the second comparison, and the third comparison is You only need to compare the number other than the last two numbers, and so on ... That is, not a trip to compare, each trip less than once, to a certain extent, reduce the amount of the algorithm.In terms of time complexity:1. If our data is in the right order, we need to take a trip to complete the sequencing. The required number of comparisons and the number of records moved to the minimum value, namely: cmin=n-1; Mmin=0; Therefore
This article illustrates the bubbling sort of Java sort algorithm summary. Share to everyone for your reference. The specific analysis is as follows:
Bubble Sort (bubblesort) is to compare the adjacent two numbers sequentially, place the decimal number in the front, and the large numbers in the back.
Let's look at t
no extreme requirement for storage space, and very confident about your basic skills, it is not advisable to implement a class similar to Bitset to implement related functions. Because the classes in the JDK are extremely streamlined and reasonably optimized, the Bitset class is relatively long.No repeat OrderJava JDK inside the container class sorting algorithm is mainly used to insert sort and merge sort
Basic idea:In the set of numbers to sort, select the minimum (or maximum) number to exchange with the 1th position, and then in the remaining number, find the smallest (or largest) number in the 2nd position, and so on, Until the first N-1 element (the penultimate number) and the nth element (the last number) are compared. Examples of simple selection sorting:Operation Method:First trip, from N records to find the minimum key
Basisinserts a record into a sorted table to get an ordered table with an additional record. And the most important point is that it moves the record larger than the current element back, to empty out the position of "own" the insertion. The record is an ordered sequence when the n-1 trip is completed.
def insertsort (Tarray)
i=1 while
(i
[2, 4, 5, 6, 7, 8, 9]>exit code:0
When
1. Bubble sort1) Principle: iterate over the sequence to be sorted, a comparison of two elements at a time, assuming they are in the wrong order to exchange them. The work of visiting the series is repeated until there is no need to exchange, that is to say, the sequence is sorted out. 2) Code implementation:Package Com.test.sort;public class bubblesort{public static void sort (int[] data) {for
Preface: About the Bubble sort and choose the sort, each time writes the time to look at their concept again, this time, writes oneself to understand1. Bubble Sort:In fact, bubble sort should be proved by example, set the array length to n.1. Compare the next two data, if the previous data is larger than the data, two data will be exchanged.2. So that the No. 0 d
-1 and I-2//Example: 1,4,8,3 after sorting 3 into 4 front 1,3,4,8Exch (A, J, j-1);//This changes the switch to the right to increase the speed a[j] = a[j-1]; } //A[j] = temp; } } /** Hill Sort*/ Public Static voidShellsort (comparable[] a) {intT =a.length; intH = 1; while(H//use 1, 4, 13, 40, 121 this hill sequence while(H >= 1) {//when H is 1 o'clock, it is actually the
together. Compared with other O (NLOGN) sorting algorithms, the run time of the merge algorithm relies heavily on the relative overhead of comparing elements and moving elements in arrays and temporary arrays. These costs are language-related.The following is the implementation code for the merge sort algorithm:Import Java.util.random;public class Sortalgorithm {/** * Merge
When there is a list of lists that are unordered, the data in the list is associated with ParentID, sorted by Java into two sort types:The test list used by the top-level no parentid, if it is a special value, modified under the judgment method can be.First sort: Sort by tree structure before sorting: 122,13,121,1,13
The Insert sort algorithm is an efficient algorithm for ordering a small number of elements. The insertion sort works similar to the way the cards are organized at cards, and when we start to draw, our left hand is empty, then one card is touched from the table and inserted into the right position of the left hand. To find the right position for this card, compar
Sorting needs to be mastered by having a bubbling sort, inserting sort and selecting sort.Bubble sort: The outer loop goes from back to front, the memory loops from the back to the outer loop, the adjacent array item 22 compares, and the larger value is moved back.Insert sort: Starts at the middle of the
The Hill sort (Shell sort) is a sort of insertion. is an improvement on the direct insertion sorting algorithm. This method is also known as narrowing the incremental sort, because of the DL. The shell was named after it was intro
Hill sort performed well for a medium-size array of up to thousands of data items, and hill sorting is not as fast as the fast sort and other time complexity O (N*LOGN) sorting algorithms, so sorting very large files is not the best choice, But Hill sort is a lot quicker than choosing sort and insert
unordered zone "2", and put it in the ordered area with the order of the elements of the area to compare, the left side of the midline is ordered, the right side of the unordered area, because of the given, the following figure is not clearly explained!!It is important to note that inserting elements in the Insert sort search for the right position does not come across an element that is smaller than the insert element, but instead records the locati
be compared, and a maximum number is also found after the number of the second comparison, and the third comparison is You only need to compare the number other than the last two numbers, and so on ... That is, not a trip to compare, each trip less than once, to a certain extent, reduce the amount of the algorithm.In terms of time complexity:1. If our data is in the right order, we need to take a trip to complete the sequencing. The required number of comparisons and the number of records moved
1 PackageCom.array;2 3 Public classSort_quick {4 /*5 * Project name: Quick sort;6 * Project requirements: Using the Java array to sort, and the use of fast sorting algorithm;7 * SEVCK;8 */9 Public voidSortintLeftintRightintarray[]) {Ten intL =Left ; One intR =Right ; A intPirot = array[(left + right)/2]; - inttemp =
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.