【JAVA】排序算法之选择排序

1.前言

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:3515dfde-2780-422e-a713-e67d423a1e55

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:2c25383f-199a-47ad-aa7e-87d3757dce51

2.思路

选择排序重在 选择二字,比如给定一串数字 5 3 4 1 2,我们选定第一位存放最小的数字,因此需要找出数字5后面所有数字 3 4 1 2中最小的数字与其交换,以此类推再完成第二个第三个直到最后一位。

3.代码

4.分析

选择排序的每一次选中最小值都需要经过N-m次循环,N为数组的总长度,m为当前排序的位置。

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:d0919fcd-1133-43f7-83d0-64c005a69216

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:58d63403-6625-440f-93b3-18fee336ebb9

最好情况:(N-1)+(N-2)+ … + 2 + 1 = N(N-1)/2 次

最坏情况:(N-1)+(N-2)+ … + 2 + 1 = N(N-1)/2 次

时间复杂度:O(n²)

空间复杂度:O(1)

Original: https://www.cnblogs.com/anlizhaomi/p/16249612.html
Author: 暗里&着迷
Title: 【JAVA】排序算法之选择排序

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/563715/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球