Lecture 1 Analysis of Algorithms
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
Analysis of Algorithms
The theoretical study of computer program?performance?and?resource?usage.
Performance: time
Resource: communication, RAM memory or disk memory and so on.
?
What's more important than performance?
Correctness, Simplicity, Maintainability, Robustness, Features, Functionality, Modularity, Security, User-friendliness.
Why study algorithm and performance?
They are the fundamental thing for above.
?
Problem: sorting
Input:?sequence <a1, a2, ..., an> of numbers
Output:?permutation <a1’, a2’, ..., an’>, s.t. a1’?<= a2’?<= ... <= an’
?
Insertion Sort:
Insertion-Sort(A,n) //Sorts A[1...n]
for j <- 2 to n
? ? do key <- A[j]
? ? ? ? i <- j - 1
? ? ? ? while i > 0 and A[i] > key
? ? ? ? ? ? do A[i+1] <- A[i]
? ? ? ? ? ? ? ? i <- i - 1
? ? ? ? A[i+1] <- key
?
?
Running time:
-Depends on input (eg. Already sorted)
-Depends on input size (6 elem. VS 6*10**9)
? ? -parameterize in input size
-Want upper bounds
? ? -guarantee to the user
?
?
Kinds of analysis
Worst-case?(usually): T(n) = max time on any input of size n.
Average-case?(sometimes): T(n) = expected time over all inputs of size n.
(Need assumption of statistic of distribution: uniform distribution)
Best-case?(bogus) cheat
?
What is insertion sort's worst-case time?
Depends on computer
-relative speed (on same machine)
-absolute speed (on different machine)
?
BIG IDEA! ?Asymptotic analysis
1.?Ignore machine dependent constants;
2.?Look at?growth?of T(n) as n ->?infinity.
?
轉(zhuǎn)載于:https://my.oschina.net/kuailechengxuyuan/blog/1926433
與50位技術(shù)專(zhuān)家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的Lecture 1 Analysis of Algorithms的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 第十八天笔记
- 下一篇: mysql数据库,创建只读用户