@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)