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.
(2) Example
(3) Implement with Java[Plain] View plain copy packagecom.njue; publicclassinserts
The first is the Eightalgorithms.java file, the code is as follows:Import java.util.arrays;/* * Implements eight commonly used sorting algorithms: Insert sort, bubble sort, select sort, Hill sort * and quick sort, merge sort, heap
Base sort
Count sort
Bucket sort
The Cardinal sort, the bucket sort, the count sort is three kinds of linear sorting method, broke through the comparison sort O (
Package Com.wang.sort;import Java.util.arrays;public class Sort {/** * 1. Direct insertion Sort * Idea: The current number is compared with the number of rows already in the previous order, and inserted into the appropriate position * @param Arra */public void Simplesort (int[] arra) {for (int i = 1; i Eight basic sort (direct insert
Direct Insert Sort:In the sequence , assume ascending sort1) start at 0.1) If you go to begin = 3, save the Begin element to TMP, compare the element at TMP with the element size relationship at begin--, and move the begin-1 element to begin if it is 3) and so on, go through the sequence sequentially.Complexity of Time: O ()The code is as follows:
Sequence in ascending order void Insertsort (int* a,int size) {assert (a);for (int begin = 0; begin 2. Hill sortThe hill
(n). Obviously, the smaller the bucket, the less data between buckets, and the less time it takes to sort. But the corresponding space consumption will increase.Best case: T (n) = O (n+k)Worst case: T (n) = O (n+k)Average condition: T (n) = O (n2)Three, Cardinal sort (Radix sort) (1) Introduction to AlgorithmsThe card
Base sort _radixsort
The idea of Cardinal sort
Implementation of radix sorting algorithm
Base sort based on count sort
Base sorting based on optimal bucket ordering
Base sort
An algorithm is a set of well-defined rules that are used to solve a problem within a finite step. Popular point, that is, the process of computer problem solving. In this process, whether the formation of a problem-solving ideas or writing programs, are in the implementation of some kind of algorithm. The former is the algorithm of inference implementation, the latter is the algorithm of operation implementation.
An algorithm should have the following five important features:
1. Poor: An algori
To sort an integer element in the ArrayList collection in ascending order:
Package org.hyp.test; Import java.util.ArrayList; Import Java.util.Random; public class Mysort {private arraylist
Insert | sort | algorithm
This article describes the four sort algorithms for C #: Bubble sort, select sort, insert sort, and Hill sort
Bubble sort
Using System;
Namespace Bubblesorter
first, direct insertion sortStability, time complexity: preferably O (n), worst O (n^2), average O (n^2). Space complexity O (1)void Insertsort (int l[], int n) {int I, j,key;for (i = 1; itwo or two points insert sortFinds the insertion position using a binary search. Stability. Best Case o (n lg N), worst and Average case O (n^2), Spatial complexity O (1).void Binsertsort (int l[], int n) {int i, J,key, Low, Mid, high;for (i = 1; i Iii. sort of HillU
before self-study data structure of the time to see the C language version of the four basic sorting method, C language is almost forgotten, recently available in PHP four sort method to re-write again, review the increasingly unfamiliar algorithm. Paste the code directly.
"; Print_r ($var); echo "";} $arr =array (33,11,22,66,55,44,88,99,77);p rintf ("* * Original array * *");p($arr);/*** Bubble sort
Select sortHow it works: each time the largest or smallest element is selected from the data element to be sorted, it is stored at the beginning of the sequence until all the data elements to be sorted are exhausted.Voidselectsort (int*a,size_tsize) {assert (a); for (inti=0;iHeap Sortonly needAscending Voidadjustdown (int*a,size_tsize,introot) { ASSERT (a);intchild=root*2+1; while (childThis article from "Write Quality or Low" blog, declined reprint!Sort
On the sorting method, the common sorting methods are insert sort, bubble sort, quick sort, select sort, merge sort, also have heap sort, bucket sort, base
12000000 (12 million) if it takes m=2500 (which saves a bit of space and has a high time efficiency).The sorting efficiency of buckets is also high.and the sorting algorithm for each bucket of buckets can also be changed to other not necessarily fast rows.The bucket sort app doesn't seem to be much, and it seems that a lot of people confuse the cardinal sort with the bucket sort.By contrast, the number of
Common sort algorithm implementations (direct insert sort, bubble sort, quick sort, build big selection Sort), and several next time write on. #include "stdio.h" #include "stdlib.h" #include "malloc.h" #include Operation Result: 3 1 14 5 2 56 67 54 77 34 This is the resu
Bubble Sort: int[] hehe={4,7,2,5,6,9,0}; for(intI=0; i){ for(intj=i+1; j){ if(hehe[i]>Hehe[j]) { inttemp=Hehe[i]; Hehe[i]=Hehe[j]; HEHE[J]=temp; } } }Insert Sortint[] a={ -,7,8,9,Ten,1,2, +}; inti,j,t,h; for(i=1; i) {T=a[i];//the number of one digit after the depositJ=i-1; while(j>=0 tA[j]) {A[j+1]=A[J];//the last digit equals the previous oneJ--; } a[j+1]=t;//if a while is made, the latter number e
one merge operation.
Code Implementation
Def merge (left, right): I, j = 0, 0 result = [] while I
8. Base sortingDescription
Base sorting (radix sort) is a type of "distribution sort", also known as "bucket sort" or "bin sort". As the name suggests, it uses some informatio
Java merge sort algorithm, bubble sort algorithm, selection sort algorithm, insert sort algorithm, description of Quick Sort Algorithm, java bubbleAn algorithm is a set of clearly defined rules used to solve a problem within a limited step. In layman's terms, it is the proce
The fast sorting method mainly utilizes a method of arrays to Arrays.sort () implementation.
Bubble method is used to compare the traversal array, through the constant comparison of the minimum or maximum value of a single traversal.
The Select Sort method is to use the first data of the array as the largest or smallest value, and then output the ordered array by comparing the loops.
The insertion sort i
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.