Sorting Algorithm - Overview

Seven commonly used sorting algorithm:

1w integers sorted tested

Insertion Sort
	 1, direct insertion sort
		 Time complexity: O (n ^ 2), the spatial complexity: O (1)
		 Code address: https: //gitee.com/phprao/sort/blob/master/insertSort.php
		 Test time: 1.1439521312714
	 2, Hill sorting
 Sort exchange
	 3, bubble sort
		 Time complexity: O (n ^ 2)
		 Code address: https: //gitee.com/phprao/sort/blob/master/normalSort.php
		 Test time: 4.0284831523895
	 4, Quick Sort
		 Time complexity: O (nlogn), the spatial complexity: O (n)
		 Code address: https: //gitee.com/phprao/sort/blob/master/quickSort.php
		 Test time: 0.013572931289673
 Selection Sort
	 5, direct selection sort
		 Code address: https: //gitee.com/phprao/sort/blob/master/pickSort.php
		 Test time: 1.5686509609222
	 6, heapsort
		 Code address: https: //gitee.com/phprao/sort/blob/master/heapSort.php
		 Test time: 0.029752969741821
 7, merge sort
	 Time complexity: O (n ^ 2)
	 Code address: https: //gitee.com/phprao/sort/blob/master/combineSort.php
	 Test time: .18463897705078

Explain the principles of:

1, direct insertion sort
be a sorted array A, an empty array B, once the elements A B into a specific position so that B is always sorted result set.

2, Hill sorting
1 on the basis of the optimized, first row to be recorded is divided into several sub-sequence insertion sort sequences, while "substantially ordered" to be recorded in the entire sequence, and then the all records to conduct a direct insertion sort.

3, bubble sort
Needless to say, right

4, fast sorting
https://blog.csdn.net/raoxiaoya/article/details/100762439

5, direct selection sort
is the name suggests selecting a minimum from each array, this result set is elected ordered, in fact, it is the minimum sequence coming out, and similar ideas bubbling, each bubble is just to find a minimum need to go through multiple exchanges to the designated location, and select the sort only need to be exchanged once.

6, heapsort
name suggests is to maintain an ordered data structure constructed by a minimum / process piles. Every time data is written to the heap, you need to adjust the local heap sort, then traverse from the pile of data is ordered, PHP standard library SplHeap provides a heap of operation, another example of Redis sorted set of data Types of.

7, merge sort
is a combination of the meanings merge two or more ordered sequences into a new ordered list. It assumed that the initial sequence contains n records, it can be seen as the n ordered subsequences, each subsequence of length 1, then merge twenty-two, orderly sequences of length 2 (or 1), and then twenty-two merge. Repeat, until a length of up to an ordered sequence of n. This sequencing method is called 2-way merge sort.
Although it looks after each sub-sequences are combined to do the sorting operation, but in fact, since the sequences are substantially ordered, sorted up time complexity is not high; deep due to the depth of recursion , so it consumes memory.

Contrast can be seen:Quick Sort with Heapsort It is the fastest.

Intelligent Recommendation

Data structure notes sorting (1) Algorithm overview

This note is organized for your own review, and can also be referenced if there are other people's needs. 1. Algorithm Basics (1)Algorithm definition: Constructed by a limited number of instructions, ...

C++ Data Structure and Algorithm Learning (I) Overview of Sorting Algorithm

1. Sorting algorithm classification: Comparison class sorting: The relative order between elements is determined by comparison. Since its time complexity cannot break O(nlogn), it is also called nonli...

Data structure and algorithm (10) Sorting algorithm overview, bubbling, quick sort

1. Overview of sorting algorithm The so-called sorting is the operation of arranging a string of records in increasing or decreasing order according to the size of one or some keywords. Sorting algori...

Sorting overview

The sorting algorithm is too important, and it is said that there are hundreds of sorting algorithms, we only study 7 kinds of classic inner sorting algorithms, they belong to four categories of algor...

Algorithm overview

algorithm The algorithm is a process in which a structure can be obtained according to certain mechanical procedures when solving a problem. The algorithm must be deterministic, efficient, and limited...

More Recommendation

[Algorithm] - Sorting and Sorting Algorithm

Count sorting algorithm In the previous sorting algorithm, the position of each element is based on direct comparison of elements, and this sorting is calledComparison rowsequence. Any comparison sort...

Sorting Algorithm Sorting Algorithm (a)

Algorithm specification and description of the problem represented by the following pseudo-code practice Input: sequence ⟨a1, a2, …, an⟩of numbers. Output: permutation ⟨a’1...

Algorithm-Sorting Algorithm-Sorting

This article is the original article of Joshua317. Please indicate: Reprinted fromJoshua317 blog https://www.joshua317.com/article/11 Algorithm-Sorting Algorithm-Sorting This article is the origi...

Overview of ten sorting algorithms

0.1 algorithm classification Ten common sorting algorithms can be divided into two categories: Nonlinear time comparison class sorting: The relative order between elements is determined by comparison....

Computer Basics Sorting--Overview

1. Overview: 1) What is a computer? Full name of computer: Electronic computer, commonly known as computer. It is a modern intelligent electronic device that can run according to the program and proce...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top