greatly improved. In addition, the use of direct insertion sorting for a smaller number of sequences increases the efficiency of the data that needs to be moved less. As a result, hill sequencing has a high execution efficiency. Hill sort is not stable, O (1) extra space, time complexity is O (n (logn) ^2). The Java code
repeated by the two small sequences separated by the datum points."Code Implementation" Public Static voidQuickSort (int[] arr,intLeftintRight ) { //if left is not less than right, the part that needs to be sorted has only one element, and the method ends the call. if(Left >=Right ) { return; } //set the leftmost element to pivot (datum point) intp =Arr[left]; //Put the smaller than p on the left side, bigg
] and a[6], greater than the first exchange. Compare 1 times in total."Code Implementation" Public classTest { Public Static voidMain (string[] args) {//given array int[] A = {49, 38, 65, 97, 76, 13, 27 }; //the outer for loop control compares the first few rounds for(inti = 0; i ) { //The inner for loop controls the number of comparisons per round, a[j] is the right-to-do element for(intj = i + 1; J ) {
does not allow the value of key to be null. is not synchronized.Hashtable: Similar to HashMap, except that the value of key and value are not allowed to be null; it supports thread synchronization, which means that only one thread can write Hashtable at any one time, thus causing the hashtale to be slower to write.Linkedhashmap: The insertion Order of the records is saved, and the first record is inserted first when traversing the linkedhashmap with
Directory (?) [+] Introduction to bubble sort algorithm
The bubble sort is simpler than the insertion sort, pushing the largest element progressively to the highest bit (currently dealing with the highest bit of the child array). As I understand it, bubble sequencing is a layer-by-layer process . The top is built, and
Download the document and own screenshots to preserve
The relationship between 8 sorts:
1, direct insertion sort
(1) Basic idea: In the set of numbers to be sorted, suppose that the front (n-1) [n>=2] number is already a row
In a good order, now you have to insert the nth number into the preceding ordered number so that the number of n
It's a good order, too. Repeat the loop until all the order is sorted.
backwards, if the array is very large, then the direct insertion of the cost is very large.5. code example: Packagesort;Importjava.util.Arrays;/*** Hill Sort * *@authorTangjiang November 24, 2017 afternoon 4:51:37 **/ Public classShellsort { Public Static voidShellsorttest (int[] arr) { if(arr = =NULL|| Arr.length ) { return; } //Set ini
in this paper, according to the "Big talk Data Structure" a book, the Implementation of Java version of the two-fork sorting tree/Two-fork search tree .Binary Sorting Tree IntroductionIn the previous blog, the efficiency of inserting and deleting sequential tables is also possible, but the search efficiency is very low, while in ordered linear tables, it is possible to use binary, interpolation, Fibonacci and other lookup methods, but because it is
Hill Sort SummaryThe hill sort is based on the following two-point nature of the insertion sort, which proposes an improved method:
The insertion sort is efficient in the case of almost sequenced data operations, i.e. the
Sorting algorithms are of various kinds, each with its own strengths, these days will be analyzed. Learning should have a progressive process, from easy to start.
First say simpler-insert sort (implemented by PHP code, here is not fastidious!) )
/*** Insert sort--sort algorithm that is slightly more complex than bubb
Package insert_sort;Import Java.util.Random;/* Various insertion sort*------Data Storage Range 1~s.length-1-------* Mainly include* Direct Insert Sort* Binary Insert Sort* Hill Sort* The following is a code implementation where th
Java sorting algorithm (vi): Direct Insert Sort The basic operation of a direct insert sort is to insert the data element to be inserted into the preceding ordered sequence by the size of its keywordDirect Insert sort time is not efficient, if in the worst case, the sum of all elements of the comparison is (0+1..n-1)
.Bubble Sort:By the comparison of the adjacent two numbers, it is necessary to decide whether to swap the two number positions, and then forward (or backward) the comparison. The simplest sort algorithm, directly on the code. for (i=0;i) for (j=i+1;j) if (arrayval[i]>arrayval[j]) { // Displacement position temp=arrayval[i]; Arrayval[i]=Arrayval[j];
PackageKpp.sort;/*** Hill Sort * 1. Set the step d, dividing every D element into a group, inserting a sort within the group; * 2.d/=2, repeat 1 steps until the step is 1 * We know once the insertion sort is stable, but during different insertion sorts, the same elements may
there is a wrong place, I hope to point out. Body
In the preface I described the steps and principles of the binary sorting algorithm, and I started with a code to implement the algorithm to analyze
public void Binarysort (t[] obj, comparator
From the above we can see that the code has two loops, the first for loop is corresponding to 2-7 steps, and the second while loop corresponds to 2-4 steps, we need
(sorted) is greater than the new element, move the element to the next position;
Repeat step 3 until you find the sorted element is less than or equal to the position of the new element;
After inserting a new element into the position;
Repeat step 2~5.
3.2 Motion Diagram Demo3.2 Code Implementation/** * Insert Sort * @param array * @return * /public static int[] Insertio
packageorg.rev.algorithm;/*** Insert Sort: Each time a record to be sorted is inserted at its size into the appropriate position of the previously sorted subsequence until all is inserted. **1. Direct Insert Sort: Compare the sorted parts to find the right location **2. Binary insertion Sort: Use dichotomy to find the
The insertion sort is also a classic sort, suitable for arrays that are already basically ordered and have a smaller amount of data. Wrote a Java version of the insert sort yourself. Please refer to the students.Package leilei.bit.edu.t2; Public classInsertsort { Public Stat
Basic idea:The essence of hill sort is grouping insertion sort, also known as narrowing increment method.The entire unordered sequence is divided into a number of sub-sequences (consisting of elements separated by an "increment") to be directly inserted into the sort, then reduced incrementally and then sorted, and the
tree.Insert procedure:If the binary sort tree is empty, the insertion node *s as the root node into the empty tree;When non-empty, will be inserted node keyword S->key and tree root keyword t->key to compare, if S->key = T->key, then no need to insert, if s->key4. Finding a two-fork sorting treeAssuming that the root node pointer of the binary sort tree is root
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.