能有效率地排序小数字的演算法.pptVIP

  • 0
  • 0
  • 约2.32千字
  • 约 14页
  • 2026-12-03 发布于重庆
  • 举报

能有效率地排序小数字的演算法

2.1InsertionSort:能有效率地排序小數字的演算法範例:5246132546132456132456131245631234562GettingStarted

2.2AnalyzingAlgorithms?RAM:Random-accessmachine,在此機器上執行記憶體存取只需一單位的時間,且指令是依序一個一個執行。?Runningtime:執行的步驟的總數量,以inputsize的函數來表示之。3GettingStarted

範例:InsertionSort Insertion-Sort(A) 1forj←2tolength[A] 2 dokey←A[j] 3 ?insertA[j]intothesorted

sequenceA[1..j-1] 4 i←j–1 5 whilei0andA[i]key 6 doA[i+1]←A[i] 7 i←i–1 8 A[i+1]←key T(n)=c1n+(c2+c4+c8)(n-1)+c5+(c6+c7)costc1c20c4c5c6c7c8timesnn-1n-1n-1n-14GettingStarted

Bes

文档评论(0)

1亿VIP精品文档

相关文档