当前位置:网站首页>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 !
边栏推荐
- Nine Qi single chip microcomputer ny8b062d single key control four LED States
- 【C】 (written examination questions) pointer and array, pointer
- 雅思考试流程、需要具体注意些什么、怎么复习?
- 同事的接口文档我每次看着就头大,毛病多多。。。
- Build your own minecraft server with fast parsing
- JS convert pseudo array to array
- 巩固表达式C# 案例简单变量运算
- 业务实现-日志写到同一个行数据里面
- 1189. Maximum number of "balloons"
- Hologres Query管理及超时处理
猜你喜欢

lambda表达式

"Xiaodeng" domain password policy enhancer in operation and maintenance

青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区

URLs and URIs

Skills in analyzing the trend chart of London Silver

lambda expressions

Robot reinforcement learning synergies between pushing and grassing with self supervised DRL (2018)

Operator explanation

Get to know ROS for the first time

【路径规划】RRT增加动力模型进行轨迹规划
随机推荐
Introduction to ACM combination counting
Cross domain request
AcWing164. 可达性统计(拓扑排序+bitset)
2022.07.03(LC_6109_知道秘密的人数)
Hologres Query管理及超时处理
Verilog tutorial (11) initial block in Verilog
skimage: imread & imsave & imshow
Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
It's too convenient. You can complete the code release and approval by nailing it!
P4408 [noi2003] truant children (tree diameter)
GDB common commands
Learning of basic amplification circuit
Multilingual Wikipedia website source code development part II
Deux nombres se remplacent
Summer challenge brings you to play harmoniyos multi terminal piano performance
JS 将伪数组转换成数组
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
Identifiers and keywords
Upload avatar on uniapp
Illustrated network: what is gateway load balancing protocol GLBP?