当前位置:网站首页>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 6108 decryption message)
- Operator explanation
- He worked as a foreign lead and paid off all the housing loans in a year
- A new method for analyzing the trend chart of London Silver
- Summary of week 22-07-02
- Deux nombres se remplacent
- Tester's algorithm interview question - find mode
- 电力运维云平台:开启电力系统“无人值班、少人值守”新模式
- [paper reading] Tun det: a novel network for meridian ultra sound nodule detection
- [论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
猜你喜欢
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
Learn C language from scratch day 024
Some basic functions of enterprise projects are developed, and important things are saved to online first a
leetcode494,474
初识ROS
How to do the project of computer remote company in foreign Internet?
基本放大电路的学习
同事的接口文档我每次看着就头大,毛病多多。。。
Deux nombres se remplacent
2022.07.03(LC_6108_解密消息)
随机推荐
【C】(笔试题)指针与数组,指针
JS how to realize array to tree
JS convert pseudo array to array
P4281 [AHOI2008]紧急集合 / 聚会(LCA)
Fast analysis -- easy to use intranet security software
Complete knapsack problem (template)
URLs and URIs
他做国外LEAD,用了一年时间,把所有房贷都还清了
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
Consolidated expression C case simple variable operation
基于三维gis平台的消防系统运用
P4408 [NOI2003] 逃学的小孩(树的直径)
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
实战模拟│JWT 登录认证
Deux nombres se remplacent
PermissionError: [Errno 13] Permission denied: ‘data. csv‘
基本放大电路的学习
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!