当前位置:网站首页>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 !
边栏推荐
- Microservice
- ORB(Oriented FAST and Rotated BRIEF)
- Kibana index, mapping, document operation
- [IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
- 如何有效对直流列头柜进行监测
- uniapp上传头像
- TS quick start - functions
- 雅思考试流程、需要具体注意些什么、怎么复习?
- C语言中sizeof操作符的坑
- 1189. Maximum number of "balloons"
猜你喜欢
![[selenium automation] common notes](/img/d3/6699792e85b5ee5a2d6192f4e4d07c.png)
[selenium automation] common notes

雅思考试流程、需要具体注意些什么、怎么复习?

圖解網絡:什麼是網關負載均衡協議GLBP?

1189. Maximum number of "balloons"

leetcode494,474

海思3559万能平台搭建:YUV422的踩坑记录

IELTS examination process, what to pay attention to and how to review?

Detailed explanation of openharmony resource management

2022.07.03(LC_6108_解密消息)

skimage: imread & imsave & imshow
随机推荐
The pit of sizeof operator in C language
Basic points of the game setup of the points mall
(script) one click deployment of any version of redis - the way to build a dream
XML的解析
Hologres Query管理及超时处理
Identifiers and keywords
Learning of basic amplification circuit
Consolidated expression C case simple variable operation
Business implementation - the log is written to the same row of data
Learn C language from scratch day 024
AcWing164. 可达性统计(拓扑排序+bitset)
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
Netcore3.1 JSON web token Middleware
P4408 [NOI2003] 逃学的小孩(树的直径)
Using fast parsing intranet penetration to realize zero cost self built website
ORB(Oriented FAST and Rotated BRIEF)
22-07-02周总结
lambda表达式
Parsing of XML
兩個數相互替換