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
--found 3 meet the requirements, then i++ found I=j, indicating that this round of movement is over. Now the base number 6 and 3 are exchanged, the result: 3 1 2 5 4 6 9 7 ten 8; now 6 The left is yet. Figure: Adam and Eve finally have a intersection(6) We take the number of the left of 6 out first: 3 1 2 5 4, this time with 3 as the base number to adjust, so that 3 left the number of 3 5 4(7) Then 2 1 key out to reorganize, the results obtained: 1 2(8) The remaining sequence on the right:
is a priority queue of a very good implementation. Through the heap, the discretionary operation on the priority queue can be implemented in the LGN time.3. Exercise 6.5-8 Solution*/* Introduction to algorithm sixth Exercise 6.5-8 * * Remove the first element of the K list as an array, constituting a minimum heap, the top element of the heap is the minimum * each time the top element of the heap is inserted at the end of the new linked list, and then the next element of the linked list of that
source, this article address: http://blog.csdn.net/zhangxiangdavaid/article/details/37668921
If this is helpful, try again!
Column Directory: Data Structure and algorithm directory
Counting sorting is a sort of buckets.
The sorting algorithm is called a ranking ?? Order, that is, to sort the record strings according to the size of one or more keywords, increment or decrement.? Category? The
Read some of the code written in introduction to algorithms and make a record.
[Cpp]# Include # Include # Include # Define maxNumber 100000000;/*------------------------------------------------------------------------* Some algorithms involved in Chapter 2-7 of Introduction to algorithms:* Insert sorting + Merge
'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
is small (such as N ≤ 50), direct insertion or direct selection of sorting can be used.When the record size is small, the direct insertion sorting is better; otherwise, the sorting should be selected because the number of records to be moved is less than the direct insertion.(2) If the initial state of the file is basically ordered (positive), direct insertion,
Simple comparison of sorting algorithms
1. Stability Comparison
Insertion sorting, Bubble sorting, binary tree sorting, two-way merge sorting, and other linear sorting are stable.
Sele
PHP implements four basic sorting algorithms and four php algorithms.
Many people say that algorithms are the core of a program. The quality of algorithms determines the quality of the program. As a beginner phper, although seldom touched on
Sorting refers to arranging the collection of elements in the specified order. There are usually two sorts of sorting methods, ascending and descending. For example, the integer set {5,2,7,1} is sorted in ascending order, the result is {1,2,5,7}, and the result is {7,5,2,1} in descending order. In general, the purpose of sorting is to make the data appear in a mo
Document directory
1) insert sorting
2) Hill sorting
3) Select sorting
4) Bubble Sorting
5) counting and sorting
6) Base sorting
7) Merge and sort
I. The preface sorting
to Sentinel 7 For (J = I- 1 ; Sentry ){ 8 Data [J + 1 ] = Data [J]; // Record move-back 9 } 10 Data [J +1 ] = Sentry; // Insert to an appropriate location 11 } 12 } 13 }
The idea of directly inserting a sort table is very simple. The length of each sort order table is increased by 1. While finding the entry and exit locations for the record, the post-shift ratio is greater (for non-descending sorting here. Analyzes the
PHP compares the running time of four basic sorting algorithms (recommended) and four algorithms
Many people say that algorithms are the core of a program. The quality of algorithms determines the quality of the program. As a beginner phper, although seldom touched on
Various sorting algorithms (serialization ...), The sorting algorithm is being serialized...
To open a new blog, start with the sorting algorithm... I try my best to start with the simplest Sorting Algorithm and occasionally upload updates ~
Ps: Before I learned JAVA and C +
1. concept I sequence statistic is the smallest element in the set. When N is an odd number, the median is the number that appears at I = (n + 1)/2. When N is an even number, the median appears at I = n/2 and I = (n + 1)/2 respectively. In this article, we ignore the parity of n. The median indicates the number at I = (n + 1)/2. This document assumes that the numbers in the set are different. Ii. Code
# Include
Iii. Exercise 9.1 min and Max 9.1-1 see Introduction to
with large O notation all require O (N2) time level. Bubbling sorting is not generally selected, although bubbling sort writing is the simplest, but the average performance is not to choose sort and insert sort well.Select sort to reduce the number of exchanges to the lowest, but the number of comparisons is quite large. Select sort can be applied when the amount of data is small and exchange data is more time-consuming than comparing the data.In mos
Algorithm is a programmer must be a skill, often appear in the interview, the following summarizes the interview in the common algorithms, these algorithms should be kept in mind, the programmer should be very skilled.Insert Sort AlgorithmPrinciple: Divide the array into unordered and ordered two regions, and then continuously insert the first element of the unordered area into the ordered area in order of
implementation features of the underlying machine(For example, kubernetes can use hardware caches better than the base ),It also depends on the input data.. In addition, counting sorting is used as the base sorting for intermediate stable sorting instead of in-situ sorting, while many sort (nlgn) Comparison
, this time will not be faster than bubble sorting.Back to top 4, summaryThe above three kinds of sorting, bubbling, selecting, inserting with large O notation all require O (N2) time level. Bubbling sorting is not generally selected, although bubbling sort writing is the simplest, but the average performance is not to choose sort and insert sort well.Select sort to reduce the number of exchanges to the low
5. Quick sorting
Quick sorting is the most common sorting algorithm, including qsort of C, sort of C ++ and Java, fast sorting is adopted (C ++ and Java sort are optimized, and other sorting algorithms are mixed ).
The worst cond
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.