当前位置:网站首页>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 !
边栏推荐
- 两个数相互替换
- Binary conversion problem
- Verilog tutorial (11) initial block in Verilog
- 同事的接口文档我每次看着就头大,毛病多多。。。
- The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
- Introduction to ACM combination counting
- 跨域请求
- A new method for analyzing the trend chart of London Silver
- URL和URI
- 图解网络:什么是网关负载均衡协议GLBP?
猜你喜欢
Some basic functions of enterprise projects are developed, and important things are saved to online first a
[selenium automation] common notes
Illustrated network: what is gateway load balancing protocol GLBP?
[IELTS reading] Wang Xiwei reading P3 (heading)
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
【C】(笔试题)指针与数组,指针
初识ROS
What did I pay for it transfer to testing post from confusion to firmness?
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
How many triangles are there in the golden K-line diagram?
随机推荐
Advanced template
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
GDB常用命令
JS how to realize array to tree
【C】 (written examination questions) pointer and array, pointer
Date time type and format in MySQL
【C】(笔试题)指针与数组,指针
挖财学院开户安全的吗?开户怎么开?
"Xiaodeng" domain password policy enhancer in operation and maintenance
[monitoring] ZABBIX
How to use fast parsing to make IOT cloud platform
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
Operator explanation
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
【路径规划】RRT增加动力模型进行轨迹规划
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
What is the difference between port mapping and port forwarding
Is it safe to open an account in the College of Finance and economics? How to open an account?
Face recognition 5- insight face padding code practice notes
业务实现-日志写到同一个行数据里面