Explanation of common sorting algorithms (code implementation, time complexity and stability)

Sort

Sort: It is to organize a group of disordered data according to a certain rule (ascending or descending order).
Sorting code: Usually data elements have multiple attribute fields that can be used to distinguish elements. As a sorting basis, this field is the sorting code. There is an attribute field that can be used to distinguish the elements according to the main sorting code, the sorting result is unique. Sort by the secondary sorting code, the sorting result may not be unique.

Sorting algorithm stability

If there are two elements R[i] and R[j] in the sequence of elements, theirSorting code K[i]== k[j]And atBefore sorting, the element R[i] is in front of R[j]. If inAfter sorting, the element R[i] is still before R[j], Then call this sortAlgorithm is stable, Otherwise the sorting algorithm is said to be unstable,
Internal sorting: Sorting where all data elements are placed in memory.
External sorting: too many data elements cannot be placed in memory at the same time. According to the requirements of the sorting process, the sorting of data cannot be moved between internal and external memory.

Common sorting algorithms

Because a blog post explains that all sorts are too large, we will explain them separately by category to ensure that the length is smaller and better accepted. Click the link below to jump to the specified sorting method.

Direct insertion sort

Hill Sort

Direct selection sort

Heap sort

Bubble Sort

Quick sort

Merge sort

Intelligent Recommendation

Time complexity of common sorting algorithms

Time complexity of common sorting algorithms Space complexity  Space Complexity (Space Complexity) is a measure of the amount of storage space that an algorithm temporarily occupies during operat...

Common sorting algorithms and their time complexity

Bubble algorithm: time complexity O(n^2), relatively stable Selection order: time complexity O(n^2), unstable ...To be updated...

The complexity, stability and code implementation of sorting algorithm

Algorithm complexity and stability Corresponding Code...

Top ten sorting unable to escape - code implementation and time complexity, spatial complexity, stability analysis

Ten sequence list Chinese name English name Average time complexity Space complexity stability Select sort Selection n^2 1 Unstable Bubble Sort Bubble n^2 1 stable Insert order Insertion n^2 1 stable ...

Summary and Java implementation of common sorting algorithms with O(N) time complexity

There are three main sorting algorithms with O(N) time complexity-bucket sorting, counting sorting and cardinal sorting, the latter two are based on the idea of ​​bucket sorting 1. Bucket sorting &mid...

More Recommendation

Summary and Java implementation of common sorting algorithms with time complexity of O(N²)

The time complexity is O(N²), there are three sorting algorithms-bubble sort, selection sort, insertion sort Bubble Sort Basic idea Suppose the array to be sorted is arr, the length is n, the out...

Several common sorting algorithms in Java (complexity, algorithm introduction, code implementation)

Write in front: Today, referring to the following article, I manually write a few codes of common sorting algorithms. This article is very clear, recommended: Several common sorting algorithms of Java...

Common sorting algorithm summary (implementation principle, stability, usage scenarios, time complexity)

Sorting algorithm Summary: The principle, time complexity, usage scenarios, stability. The principle of bubble sort: relatively simple, not described. Stability: Stable Usage scenarios: for small n si...

Java implements eight classic sorting algorithms and their complexity, stability and code analysis

One, insertion sort 1.1 Direct insertion sort Space complexity:。 time complexity:. In the best case, the elements in the table are already in order. At this time, every time you insert an element, you...

Eight sorting algorithm ideas, time complexity, stability, and java implementation

Eight sorting algorithm ideas, time complexity, stability, and java implementation One, merge sort 2. Insertion sort-direct insertion sort Three, insertion sort-Hill sort Fourth, exchange sort-bubble ...

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

Top