当前位置:网站首页>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 !
边栏推荐
- 2022.07.03(LC_6111_统计放置房子的方式数)
- Complete knapsack problem (template)
- Is it safe to open and register new bonds? Is there any risk? Is it reliable?
- Significance of acrel EMS integrated energy efficiency platform in campus construction
- P3304 [SDOI2013]直径(树的直径)
- Summer challenge brings you to play harmoniyos multi terminal piano performance
- 2022.07.03(LC_6109_知道秘密的人数)
- How to use fast parsing to make IOT cloud platform
- 挖财学院开户安全的吗?开户怎么开?
- 初识ROS
猜你喜欢
Application of fire fighting system based on 3D GIS platform
【路径规划】RRT增加动力模型进行轨迹规划
基本放大电路的学习
Operator explanation
图解网络:什么是网关负载均衡协议GLBP?
Face recognition 5- insight face padding code practice notes
Oracle case: SMON rollback exception causes instance crash
OpenHarmony资源管理详解
海思3559万能平台搭建:YUV422的踩坑记录
Detailed explanation of openharmony resource management
随机推荐
If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
他做国外LEAD,用了一年时间,把所有房贷都还清了
It's too convenient. You can complete the code release and approval by nailing it!
IELTS examination process, what to pay attention to and how to review?
Cross domain request
【路径规划】RRT增加动力模型进行轨迹规划
js如何实现数组转树
NPM install error forced installation
Introduction to ACM combination counting
圖解網絡:什麼是網關負載均衡協議GLBP?
Distributed base theory
打新债开户注册安全吗?有没有风险的?靠谱吗?
How to do the project of computer remote company in foreign Internet?
[IELTS reading] Wang Xiwei reading P4 (matching1)
The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
挖财学院开户安全的吗?开户怎么开?
Application of fire fighting system based on 3D GIS platform
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
初识ROS
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?