Next article: the programmer must know the 8 largest sorting (1) ------- Insert the sorting directly, and the hill sorting (implemented in Java ).
3. Simple selection and sorting
(1) Basic Idea: In the number of groups to be sorted, select the minimum number and the number at the first position;
Then find the smallest
Simple selection
UnstableWorst Time: O (N)Average time: O (N)Best time: O (N)Space: O (1)
#include
Heap sorting
UnstableWorst Time: O (nlogn) [The heap is a complete binary tree. The execution time of the downward adjustment function adjustdown cannot exceed O (logn). Therefore, the worst time for heap creation is O (logn ), the worst time of the operation is O (n). ajustdown is called every time a record is output, so the execution time O (nlogn).
'Heap sorting
Option explicit
Dim result, I
Dim testdata (100)
Const n= 100
Randomize
For I = 0 to n-1
Testdata (I) = round (RND () * 32768)
Next
'Heap sorting
Sub hsort (byref array, low, hi)
Dim I, T, J, P, L, R
For I = Hi to low + 1 step-1
J = I
P = int (J-low + 1)/2) + low-1
T = array (j)
Do
If P = low-1 then
Exit do
End if
If T> array (p) then
Array (j) = array (P)
J = P
P = int (J-low + 1)/2) + low
The idea of fast sorting is as follows:
If I pick out a number from an array (usually the first number), I can use this number to divide the array into two parts: the part greater than this number and the part smaller than this number. Then, repeat the previous steps for the two parts until each part has only two numbers left. We can compare them. It is a recursive program, but the difficulty of the program is: how to divide the array into two parts b
1. algorithm ideas
Quick sorting is a sort by Division and exchange proposed by C. R. A. Hoare in 1962. It adopts a sub-Governance Policy, usually called divide-and-conquermethod ).
(1) Basic Idea of divide and conquer LawThe basic idea of the division and control law is to break down the original problem into several subproblems with smaller sizes but similar structures as the original problem. Recursively solve these subproblems, and then combine t
Php sorting algorithm (bubble sorting, fast sorting ). Principle of bubble sorting ① first put all the numbers to be sorted into the work list. ② Check one by one from the first number in the list to the second to the last number.
① Put all the numbers to be sorted into the work list.② From the first number in the lis
Straight selection sort)Basic Idea of directly selecting sortingThe Direct selection and sorting of files with N records can be directly selected and sorted through n-1 rows to get the ordered results:① Initial status: the disordered area is R [1. N], and the ordered area is empty.② Sorting by 1st bitsIn the unordered zone R [1 .. n] selects the record R [k] with the minimum keyword, swaps it with the 1st r
Catalogue
Toilet sort (sickening sort)
Bubble sort (algorithm to ask for interview)
Quick sort (witness the love Journey of Adam and Eve)
toilet sort (sickening sort)first, the scene: The final exam is over, the teacher to the students score from high to low sort. Suppose the class has 5 students, respectively, 5 points, 3 points, 5 points, 2 points and 8 points "full score: 10 points", the result of sorting is 8 5 5 3 2, now, le
(1) Definition of enumeration and invocation of elements#import (2) Sorting of arrays, sortedarrayusing ... Nsarray *[email protected][@ "One", @ "one", @ "three"]; Because this array is an immutable group, it is not possible to make any changes to the alignment, and of course, the following method returns a new value [arr1 sortedarrayusingselector: @selector (compare:)]; We can completely overwrite the previous value with
Sorting Algorithm Summary: directly select sorting and Sorting Algorithm SummaryConcept
Take the smallest record in the last n-I + 1 (I =,..., n-1) as the I record of the ordered table.
Dynamic Effect:
Advantage: the algorithm is simple and easy to implement.
Disadvantage: only one element can be determined at a time.Java implementation:
Package com. liuhao. so
Review data structure: Sorting (1) -- insert sorting and data structure sorting
Starting from this article, I began to review the knowledge points of the data structure. The blog mainly focuses on the core idea of each knowledge point and code implementation. This article begins with the insertion sorting in the
Explanation of Direct selection and sorting of PHP sorting algorithm series, and explanation of php sorting algorithm series
Select sort directly
The basic idea of Straight Select Sorting is: the first time from R [0] ~ Select the minimum value in R [n-1] and exchange it with R [0]. The second time is from R [1] ~ Sele
Insert sorting in the PHP sorting algorithm series, and php Sorting Algorithm
Insert sort
There is an ordered data sequence that requires inserting a number in the sorted data sequence, but the data sequence is still ordered after insertion, in this case, we need to use a new sorting method-insert
Today I think about a problem. By the way, I think about external sorting and share it as follows:
Assuming that there are 16 numbers on the disk, and the memory can only hold four numbers for sorting, what is the difference between the sort of merging and the sort of the bucket? In fact, each has its own merits. Merge Sorting is undoubtedly the most commonly use
6. Fast sorting and sorting of comparative sorting
Quick sorting (quick sorting for short) is often used in pen questions because of its high efficiency (average O (nlogn.
The first step of the quick rank is to select a "base", which will be used for comparison and exchange
JS and jquery sorting implementation:
Key: the simplest way to achieve sorting is
Use jqueryRead object Array
Sort object arrays by JS(Sort object arrays and do not try to directly change the content of the webpage)
Overwrite the tag array on the webpage with the object array content;
// Sort the VaR arr_a = new array (); var I = 0; $ (". type_list_txt> span: Contains ('t shirt ')"). parent ().
Basic Idea of bubble sort (1): In the number of a group to be sorted, the number of all numbers in the range not sorted yet, from top to bottom, compare and adjust the adjacent two numbers in sequence, so that a large number will sink and a small number will go up. That is, when the numbers of two adjacent parties are compared and their sorting and sorting requirements are opposite, they are exchanged. (2)
Crazy Java algorithms-insert sorting, Merge Sorting, and Parallel Merge SortingSince ancient times, there has been a difficult question in the IT session, commonly known as sorting. Whether you take a high-end test such as BAT or a grassroots test hidden in the streets, you will often see such a problem that is hard to solve for a hundred years. Today, LZ has the
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.