码迷,mamicode.com
首页 > 其他好文 > 详细

sorting algorithm

时间:2015-02-09 22:46:57      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

Sorting algorithm

Selection sort


 This method is called selection sort because it works by repeatedly selecting the smallest remaining item。

 Selection sort uses ~N2/2 compares and N exchanges to sort an array of length N.

  1.  First, find the smallest item in the array, and exchange it with the first entry。
  2.  Then, find the next smallest item and exchange it with the second entry。
  3.  Continue in this way until the entire array is sorted。

技术分享

 source code: Selection.java

 结论:

  •  算法运行时间和输入无关。这意味着即使输入的数组有序,也要进行一趟扫描。

  • 数据的移动最少。交换次数和数组大小是线性关系。

insert sort


 

sorting algorithm

标签:

原文地址:http://www.cnblogs.com/luochuanghero/p/4282523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!