当前位置:网站首页>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 !
边栏推荐
- Application of multi loop instrument in base station "switching to direct"
- Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
- IELTS examination process, what to pay attention to and how to review?
- OpenHarmony资源管理详解
- NPM install error forced installation
- Parsing of XML
- The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
- [monitoring] ZABBIX
- npm install报错 强制安装
- The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
猜你喜欢

Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
![[IELTS reading] Wang Xiwei reading P4 (matching1)](/img/91/1b3f85410035f65acb0c205185f698.png)
[IELTS reading] Wang Xiwei reading P4 (matching1)

How to avoid arc generation—— Aafd fault arc detector solves the problem for you

Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system

微服务(Microservice)那点事儿

Binary conversion problem
![[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation](/img/41/eb790e7419a158e985fa503bd7dc17.png)
[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation

Application of fire fighting system based on 3D GIS platform
![[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection](/img/25/e2366cabf00e55664d16455a6049e0.png)
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection

Using fast parsing intranet penetration to realize zero cost self built website
随机推荐
How to effectively monitor the DC column head cabinet
P4281 [AHOI2008]紧急集合 / 聚会(LCA)
分布式BASE理论
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
[IELTS reading] Wang Xiwei reading P3 (heading)
Life is changeable, and the large intestine covers the small intestine. This time, I can really go home to see my daughter-in-law...
Significance of acrel EMS integrated energy efficiency platform in campus construction
Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention
Acwing164. Accessibility Statistics (topological sorting +bitset)
Netcore3.1 JSON web token Middleware
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
Using fast parsing intranet penetration to realize zero cost self built website
Illustrated network: what is gateway load balancing protocol GLBP?
Acrel-EMS综合能效平台在校园建设的意义
兩個數相互替換
OpenHarmony资源管理详解
Consolidated expression C case simple variable operation
基本放大电路的学习
Kibana index, mapping, document operation