【演算法導論】 學習筆記
阿新 • • 發佈:2021-11-27
本系列會根據《演算法導論》(Introduction to Algorithms)出版社 麻省理工學院出版社第三版作者是托馬斯·科爾曼(Thomas H. Cormen)、查爾斯·雷瑟爾森(Charles E. Leiserson)、羅納德·李維斯特(Ronald L. Rivest)、克利福德·斯坦(Clifford Stein)。
以及 B站視訊https://www.bilibili.com/video/BV1Tb411M7FA 進行學習
會採用虛擬碼 和 PYTHON 語法進行實現
It's tons of fun ! ! !
第二章 演算法基礎
2.1 插入排序(Insertion sort)
input < a_1,a_2 .....a_n>
output<a_1',a_2'......a_n'>
we want to get a new sequence from min to max
---- a_1' <a_2' <.......<a_n'
for j = 2 to A.length key = A[j] i = j - 1 while i > 0 and A[i] > key A[i+1] = A[i] i = i - 1 A[i + 1] =key
上述程式碼稱之為虛擬碼
我們不去過多的考慮他的語法嚴謹性而是去考慮他的內容
MIT 教授 說
perfermance (效能) is like money
就像 we pay perfermance for object-obriened
我們花費效能從Java中購買了一些功能 像面向物件等
A = [5, 2, 4, 6, 1, 3] for j in range(1, len(A)): key = A[j] # 2 4 6 1 3 i = j - 1 while i >= 0 and A[i] > key: # 這個迴圈體是讓這個值不停向左移動 直到上述判斷不成立A[i + 1] = A[i] i -= 1 A[i + 1] = key