当前位置:网站首页>Sorting selection sorting
Sorting selection sorting
2022-07-05 00:28:00 【Building Zzzz】
Catalog
One 、 What is selective sorting
3、 ... and 、 Time complexity , Spatial complexity and stability
Four 、 Bidirectional selection sorting ( Understanding can )
Preface
Previously, we introduced insertion sorting , Today we will learn about other common sorting , That is, select sorting , Selection sorting includes direct selection sorting and heap sorting , And today we mainly learn to choose sorting directly , Its idea is relatively simple !
One 、 What is selective sorting
As the name suggests, select sorting is to select the elements to sort , If you want to sort in ascending order, choose the smallest , In descending order, choose the largest , Exchange with the first element of the sequence , Then the whole sequence can be ordered again and again .

Two 、 Use code to implement
public class Choice {
/**
* Selection sort
* @param array Sequence to be sorted
*/
public static void selectSort(int[] array) {
for (int i = 0; i < array.length; i++) {
int minIndex = i;
for (int j = i + 1; j < array.length; j++) {
if(array[j] < array[minIndex]){
minIndex = j;// Record the minimum subscript
}
}
int tmp = array[minIndex];
array[minIndex] = array[i];
array[i] = tmp;
}
}
}3、 ... and 、 Time complexity , Spatial complexity and stability
Time complexity :O(N^2) Whether optimized or not, it is O(N^2) After optimization, only unnecessary exchanges are reduced
Spatial complexity :O(1) No more memory is used
stability : unstable There was a jump exchange
Four 、 Bidirectional selection sorting ( Understanding can )
summary
The sorting of this choice is still very simple , Just know how to choose and sort , Another option is sorting : Heap sorting is more interesting , It is also a more important sort , Therefore, selecting sorting directly can lay a foundation for the following heap sorting , Facilitate the learning of heap sorting later !
边栏推荐
- How to avoid arc generation—— Aafd fault arc detector solves the problem for you
- AcWing164. 可达性统计(拓扑排序+bitset)
- How to save your code works quickly to better protect your labor achievements
- Upload avatar on uniapp
- The pit of sizeof operator in C language
- Detailed explanation of openharmony resource management
- 企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
- P3304 [sdoi2013] diameter (diameter of tree)
- He worked as a foreign lead and paid off all the housing loans in a year
- How many triangles are there in the golden K-line diagram?
猜你喜欢

ORB(Oriented FAST and Rotated BRIEF)

lambda表达式

Continuous modification of business scenario functions

How to use fast parsing to make IOT cloud platform
Date time type and format in MySQL

基于三维gis平台的消防系统运用

他做国外LEAD,用了一年时间,把所有房贷都还清了

abc 258 G - Triangle(bitset)
![P3304 [sdoi2013] diameter (diameter of tree)](/img/5c/984675bf4517481f80f54657c6c7ad.png)
P3304 [sdoi2013] diameter (diameter of tree)

OpenHarmony资源管理详解
随机推荐
URL和URI
Verilog tutorial (11) initial block in Verilog
如何有效对直流列头柜进行监测
圖解網絡:什麼是網關負載均衡協議GLBP?
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
How to save your code works quickly to better protect your labor achievements
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
Significance of acrel EMS integrated energy efficiency platform in campus construction
Application of multi loop instrument in base station "switching to direct"
同事的接口文档我每次看着就头大,毛病多多。。。
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
多回路仪表在基站“转改直”方面的应用
挖财学院开户安全的吗?开户怎么开?
Upload avatar on uniapp
Complete knapsack problem (template)
Acrel-EMS综合能效平台在校园建设的意义
How to avoid arc generation—— Aafd fault arc detector solves the problem for you
P4281 [AHOI2008]紧急集合 / 聚会(LCA)
Build your own minecraft server with fast parsing