当前位置:网站首页>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 !
边栏推荐
- 多回路仪表在基站“转改直”方面的应用
- 业务场景功能的继续修改
- Acrel-EMS综合能效平台在校园建设的意义
- It's too convenient. You can complete the code release and approval by nailing it!
- Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
- GDB common commands
- leetcode494,474
- Paper notes multi UAV collaborative monolithic slam
- [selenium automation] common notes
猜你喜欢
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
【路径规划】RRT增加动力模型进行轨迹规划
leetcode494,474
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
Get to know ROS for the first time
微服务(Microservice)那点事儿
How to avoid arc generation—— Aafd fault arc detector solves the problem for you
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
Application of multi loop instrument in base station "switching to direct"
随机推荐
Leetcode70 (Advanced), 322
Date time type and format in MySQL
[path planning] RRT adds dynamic model for trajectory planning
Binary conversion problem
2022.07.03(LC_6111_统计放置房子的方式数)
Skills in analyzing the trend chart of London Silver
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
基于三维gis平台的消防系统运用
Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
GDB常用命令
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
He worked as a foreign lead and paid off all the housing loans in a year
[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
GDB common commands
"Xiaodeng" domain password policy enhancer in operation and maintenance
Enterprise application business scenarios, function addition and modification of C source code
JS convert pseudo array to array
JS how to realize array to tree
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
P4408 [noi2003] truant children (tree diameter)