大O表示法演算法複雜度速查表(Big-O Algorithm Complexity Cheat Sheet)
原文網址:http://bigocheatsheet.com/
Word文件下載:http://download.csdn.net/detail/anshan1984/5583399
Searching(搜尋演算法)
Algorithm(演算法) |
Data Structure (資料結構) |
Time Complexity (時間複雜度) |
Space Complexity (空間複雜度) |
|
|
|
Average(平均) | Worst(最差) |
Worst(最差) |
Graph of |V| vertices and |E| edges |
- |
O(|E| + |V|) |
O(|V|) |
|
Graph of |V| vertices and |E| edges |
- |
O(|E| + |V|) |
O(|V|) |
|
Sorted array of n elements |
O(log(n)) |
O(log(n)) |
O(1) |
|
Array |
O(n) |
O(n) |
O(1) |
|
using a Min-heap as priority queue(Dijkstra最短路徑,使用最小堆作為優先佇列) |
Graph with |V| vertices and |E| edges |
O((|V| + |E|) log |V|) |
O((|V| + |E|) log |V|) |
O(|V|) |
Shortest path by Dijkstra, |
Graph with |V| vertices and |E| edges |
O(|V|^2) |
O(|V|^2) |
O(|V|) |
Graph with |V| vertices and |E| edges |
O(|V||E|) |
O(|V||E|) |
O(|V|) |
Sorting(排序演算法)
Algorithm(演算法) |
Data Structure(資料結構) |
Time Complexity(時間複雜度) |
Worst Case Auxiliary Space Complexity (最差額外消耗空間複雜度) |
||
|
|
Best |
Average |
Worst |
Worst |
(快速排序) |
Array(陣列) |
O(n log(n)) |
O(n log(n)) |
O(n^2) |
O(n) |
(歸併排序) |
Array |
O(n log(n)) |
O(n log(n)) |
O(n log(n)) |
O(n) |
(堆排序) |
Array |
O(n log(n)) |
O(n log(n)) |
O(n log(n)) |
O(1) |
(氣泡排序) |
Array |
O(n) |
O(n^2) |
O(n^2) |
O(1) |
(插入排序) |
Array |
O(n) |
O(n^2) |
O(n^2) |
O(1) |
(選擇排序) |
Array |
O(n^2) |
O(n^2) |
O(n^2) |
O(1) |
(桶排序) |
Array |
O(n+k) |
O(n+k) |
O(n^2) |
O(nk) |
(基數排序) |
Array |
O(nk) |
O(nk) |
O(nk) |
O(n+k) |
Heaps(堆)
Heaps |
Time Complexity(時間複雜度) |
|||||||
|
Heapify |
Find Max |
Extract Max |
Increase Key |
Insert |
Delete |
Merge |
|
(有序連結串列) |
- |
O(1) |
O(1) |
O(n) |
O(n) |
O(1) |
O(m+n) |
|
(無序連結串列) |
- |
O(n) |
O(n) |
O(1) |
O(1) |
O(1) |
O(1) |
|
(二叉堆) |
O(n) |
O(1) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(m+n) |
|
(多項式堆) |
- |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
|
(斐波那契堆) |
- |
O(1) |
O(log(n)) |
O(1) |
O(1) |
O(log(n)) |
O(1) |
|
Graphs(圖)
Node / Edge Management |
Storage |
Add Vertex |
Add Edge |
Remove Vertex |
Remove Edge |
Query |
(鄰接表) |
O(|V|+|E|) |
O(1) |
O(1) |
O(|V| + |E|) |
O(|E|) |
O(|V|) |
(關聯表) |
O(|V|+|E|) |
O(1) |
O(1) |
O(|E|) |
O(|E|) |
O(|E|) |
(鄰接矩陣) |
O(|V|^2) |
O(|V|^2) |
O(1) |
O(|V|^2) |
O(1) |
O(1) |
(關聯矩陣) |
O(|V|⋅|E|) |
O(|V|⋅|E|) |
O(|V|⋅|E|) |
O(|V|⋅|E|) |
O(|V|⋅|E|) |
O(|E|) |
Data Structures(資料結構)
Data Structure (資料結構) |
Time Complexity (時間複雜度) |
Space Complexity (空間複雜度) |
|||||||
|
Average(平均) |
Worst(最差) |
Worst(最差) |
||||||
|
Indexing |
Search |
Insertion |
Deletion |
Indexing |
Search |
Insertion |
Deletion |
|
(基本陣列) |
O(1) |
O(n) |
- |
- |
O(1) |
O(n) |
- |
- |
O(n) |
(動態陣列) |
O(1) |
O(n) |
O(n) |
O(n) |
O(1) |
O(n) |
O(n) |
O(n) |
O(n) |
(單鏈表) |
O(n) |
O(n) |
O(1) |
O(1) |
O(n) |
O(n) |
O(1) |
O(1) |
O(n) |
(雙鏈表) |
O(n) |
O(n) |
O(1) |
O(1) |
O(n) |
O(n) |
O(1) |
O(1) |
O(n) |
(跳躍表) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(n) |
O(n) |
O(n) |
O(n) |
O(n log(n)) |
(雜湊表) |
- |
O(1) |
O(1) |
O(1) |
- |
O(n) |
O(n) |
O(n) |
O(n) |
(二叉查詢樹) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(n) |
O(n) |
O(n) |
O(n) |
O(n) |
(笛卡爾樹) |
- |
O(log(n)) |
O(log(n)) |
O(log(n)) |
- |
O(n) |
O(n) |
O(n) |
O(n) |
(B樹) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(n) |
(紅黑樹) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(n) |
(伸展樹) |
- |
O(log(n)) |
O(log(n)) |
O(log(n)) |
- |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(n) |
(AVL平衡樹) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(log(n)) |
O(n) |
Notation for asymptotic growth(漸進增長表示法)
Letter(字母) |
Bound(限制) |
Growth(增長) |
(theta) Θ |
upper and lower, tight[1] |
equal[2] |
(big-oh) O |
upper, tightness unknown |
less than or equal[3] |
(small-oh) o |
upper, not tight |
less than |
(big omega) Ω |
lower, tightness unknown |
greater than or equal |
(small omega) ω |
lower, not tight |
greater than |
[1] Big O is the upper bound,while Omega is the lower bound. Theta requires both Big O and Omega, so that'swhy it's referred to as atight bound (it must be boththe upper and lower bound). For example, an algorithm taking Omega(n log n)takes at least n log n time but has no upper limit. An algorithm taking Theta(nlog n) is far preferential since it takes AT LEAST n log n (Omega n log n) andNO MORE THAN n log n (Big O n log n).SO
大O是漸進上界,Ω是漸進下界。Θ需同時滿足大O和Ω,故稱為確界(必須同時符合上界和下界)。如,演算法Ω(nlogn)消耗至少nlogn時間,但是沒有上限。優先選擇演算法Θ(nlogn),因為它消耗至少nlogn(Ω(nlogn)),且不超過nlogn(O(nlogn))。
[2] f(x)=Θ(g(n)) means f (the running time of the algorithm) grows exactly like g when n (input size) gets larger. In other words, the growth rate of f(x) is asymptotically proportional to g(n).
f(x)=Θ(g(n))表示當n變大時,f(演算法執行時間)的增長與g嚴格相同。即,f(x)增長率漸進正比於g(n)。
[3] Same thing. Here the growth rate is no faster than g(n). big-oh is the most useful because represents the worst-case behavior.
同樣,這裡增長率不超過g(n)。O極其有用,因為它表示了最差效能。
In short, if algorithm is __ then its performance is __
algorithm |
performance |
o(n) |
< n |
O(n) |
≤ n |
Θ(n) |
= n |
Ω(n) |
≥ n |
ω(n) |
> n |
Big-O Complexity Chart