当前位置:网站首页>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 !
边栏推荐
- 电力运维云平台:开启电力系统“无人值班、少人值守”新模式
- 业务实现-日志写到同一个行数据里面
- Continuous modification of business scenario functions
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
- Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
- 【路径规划】RRT增加动力模型进行轨迹规划
- js如何实现数组转树
- 海思3559万能平台搭建:YUV422的踩坑记录
- 【selenium自动化】常用注解
- Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
猜你喜欢

IT转测试岗,从迷茫到坚定我究竟付出了什么?

leetcode518,377

OpenHarmony资源管理详解

《论文笔记》Multi-UAV Collaborative Monocular SLAM

What did I pay for it transfer to testing post from confusion to firmness?

基本放大电路的学习

【雅思阅读】王希伟阅读P4(matching1)
![[paper reading] Tun det: a novel network for meridian ultra sound nodule detection](/img/25/e2366cabf00e55664d16455a6049e0.png)
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection

How to effectively monitor the DC column head cabinet
![[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation](/img/41/eb790e7419a158e985fa503bd7dc17.png)
[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
随机推荐
"Xiaodeng" domain password policy enhancer in operation and maintenance
圖解網絡:什麼是網關負載均衡協議GLBP?
leetcode494,474
How many triangles are there in the golden K-line diagram?
Verilog tutorial (11) initial block in Verilog
It's too convenient. You can complete the code release and approval by nailing it!
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
Acwing164. Accessibility Statistics (topological sorting +bitset)
Recursive execution mechanism
uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
【路径规划】RRT增加动力模型进行轨迹规划
巩固表达式C# 案例简单变量运算
[IELTS reading] Wang Xiwei reading P4 (matching1)
Application of fire fighting system based on 3D GIS platform
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
TS quick start - functions
Life is changeable, and the large intestine covers the small intestine. This time, I can really go home to see my daughter-in-law...
Summer challenge brings you to play harmoniyos multi terminal piano performance
Build your own minecraft server with fast parsing
Hologres query management and timeout processing