Complexity
分析演算法好壞取決於不同角度:
時間複雜度(Time Complexity )
空間複雜度(Space Complexity)
Magnitude order
當 n 越大的時候的函數趨勢:
Polynomial Time
An algorithm is said to be of polynomial time if its running time is upper bounded by a polynomial expression in the size of the input for the algorithm. ex,
Exponential Time
時間複雜度不能被 Polynomial function bound 住的,
Pitfall: 當有兩個演算法分別是 與 ,則後者一定跑得比較快?
NO! 這個問題的關鍵在於 n 的大小,當 n 極大或是超過某個 n0 後,前者會呈指數上升,但是如果 n 極小的話, 前者是有可能較快的
example: ,則 都是前者較快
Notation
Big-O
存在正數,使得對於所有, 都符合 的集合
,includes all functions that are upper bounded by
一個演算法的 Upper-bound 取決於 worst case running time.
Big-Omega
存在正數,使得對於所有, 都符合 的集合
,includes all functions that are lower bounded by
Theory of Computation
f(n) = Ω(g(n)) <-> g(n) = O(f(n))
Last updated