当前位置:网站首页>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 !
边栏推荐
- Application of fire fighting system based on 3D GIS platform
- Tester's algorithm interview question - find mode
- Detailed explanation of openharmony resource management
- C语言中sizeof操作符的坑
- Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
- What is the difference between port mapping and port forwarding
- Parsing of XML
- Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention
- 【北京大学】Tensorflow2.0-1-开篇
- abc 258 G - Triangle(bitset)
猜你喜欢

Deux nombres se remplacent

Using fast parsing intranet penetration to realize zero cost self built website

Fast analysis -- easy to use intranet security software

微服务(Microservice)那点事儿

两个数相互替换
![[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])](/img/83/63296108b47eda37c19b9ff9deb5ec.png)
[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])

JS how to realize array to tree

Parsing of XML

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

如何有效对直流列头柜进行监测
随机推荐
[IELTS reading] Wang Xiwei reading P4 (matching1)
uniapp上传头像
Five papers recommended for the new development of convolutional neural network in deep learning
Is it safe to open an account in the College of Finance and economics? How to open an account?
Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
OpenHarmony资源管理详解
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
电力运维云平台:开启电力系统“无人值班、少人值守”新模式
[selenium automation] common notes
C语言中sizeof操作符的坑
初识ROS
Complete knapsack problem (template)
Build your own minecraft server with fast parsing
Identifiers and keywords
P4281 [ahoi2008] emergency assembly / gathering (LCA)
巩固表达式C# 案例简单变量运算
IT转测试岗,从迷茫到坚定我究竟付出了什么?
Actual combat simulation │ JWT login authentication
Get to know ROS for the first time