Java 选择排序 (Selection Sort)
来源:互联网 发布:爱知学院大学 编辑:程序博客网 时间:2024/06/06 19:26
- 选择排序原理
- 代码
选择排序原理
选择排序(Selection sort)是一种简单直观的排序算法。它的工作原理是每一次从待排序的数据元素中选出最小(或最大)的一个元素,存放在序列的起始位置,直到全部待排序的数据元素排完。
代码
public int[] selectionSort(int[] A) { if (A == null) { return A; } for (int i = 0; i < A.length-1; i++) { int min = i; for (int j = i + 1; j < A.length; j++) { if (A[min] > A[j]) { //记录最小值的下标 min = j; } } int temp = A[i]; A[i] = A[min]; A[min] = temp; } return A;}
从选择排序的思想或者是上面的代码中,我们都不难看出,寻找最小的元素需要一个循环的过程,而排序又是需要一个循环的过程。因此显而易见,这个算法的时间复杂度也是O(n*n)的。这就意味值在n比较小的情况下,算法可以保证一定的速度,当n足够大时,算法的效率会降低。并且随着n的增大,算法的时间增长很快。因此使用时需要特别注意。
0 0
- Java 选择排序 (Selection Sort)
- java选择排序Selection Sort
- 选择排序(selection sort)
- 选择排序(selection sort)
- 选择排序(selection sort)
- 选择排序(Selection Sort)
- 选择排序(Selection Sort)
- 选择排序(selection sort)
- Selection Sort(选择排序)
- 选择排序(selection sort)
- 选择排序(Selection Sort)
- selection sort 选择排序
- 选择排序 Selection Sort
- 选择排序(Selection Sort)
- 选择排序(Selection Sort)
- 选择排序 (Selection Sort)
- 选择排序(Selection sort)
- 选择排序 (Selection sort)
- SSH:Hibernate框架(Hibernate集合Map关系映射)
- Mybatis逆向工程
- 性能分析工具Eclipse Memory Analyzer tool(MAT)
- 学习笔记之递归和分治思想
- 内存泄露入门之基础知识篇
- Java 选择排序 (Selection Sort)
- MySQLConnector/C++连接方式二
- IOS开发系列--无限循环的图片浏览器
- 《大话数据结构》之Kruskal算法
- javaWeb 复习系列(二)
- sublime 快捷键大全
- Response.Flush和Response.BufferOutput
- LeetCode题解——Evaluate Reverse Polish Notation
- 安卓中轻量级数据库SQLite的使用