@CopyLeft by ICANTH,I Can do ANy THing that I CAN THink!~
Author:WenHui,WuHan University,2012-6-12
PDF版下载地址:http://www.docin.com/p1-422100846.html
一、程序源码(Python)
二、算法分析
由于该算法简单,故仅分析其平均复杂度,其平均复杂度为:
平均分析
·比较次数
假设插入第
个元素时,其插入位置为
,1 <=
<= K。其需比较
次,故其平均比较次数为:
插入N个元素时,算法总平均比较次数为:
·赋值次数
假设插入第
个元素时,其插入位置为
,1 <=
<= K – 1(当插入位置
=
时,则无需对数组进行赋值操作)。其赋值次数为:
。故插入N个元素时,算法总平均赋值次数为:
证毕。
随机分析
·比较次数
即表示:在排列A的第p个位置之前,大于A[p]值的元素总数。
故插入N个元素时,算法总平均赋值次数step1为:
故算法总平均赋值次数step2为:
证毕。
参考资料
http://www.cse.ust.hk/faculty/golin/COMP271Sp03/Notes/Ins_Sort_Average_Case.pdf
http://courses.cs.vt.edu/~cs3114/Spring10/Notes/T14.SortingAnalysis.pdf

![clip_image002[6] clip_image002[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNDg1NTMyNjEuanBn.png)
![clip_image012[6] clip_image012[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNDkwOTkyMDcuanBn.png)
![clip_image014[6] clip_image014[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNDkxNDgzMDcuanBn.png)
![clip_image018[6] clip_image018[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNDkzNDkzNDAuanBn.png)
![clip_image034[6] clip_image034[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNDk1Nzg3MTkuanBn.png)
![clip_image036[6] clip_image036[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNDk1ODI3ODguanBn.png)
![clip_image046[6] clip_image046[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNTAxMjgzNTIuanBn.png)
![clip_image052[6] clip_image052[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNTAyNTUwMDUuanBn.png)
![clip_image054[6] clip_image054[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNTAyOTUxNy5qcGc=.png)
![clip_image056[6] clip_image056[6]](/image/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vY25ibG9nc19jb20vaWNhbnRoLzIwMTIwNi8yMDEyMDYxMjEzNTAzNDU5NjMuanBn.png)