大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(最差)

Depth First Search (DFS)(深度优先搜索)

Graph of |V| vertices and |E| edges

-

O(|E| + |V|)

O(|V|)

Breadth First Search (BFS)(广度优先搜索)

Graph of |V| vertices and |E| edges

-

O(|E| + |V|)

O(|V|)

Binary search(二分查找)

Sorted array of n elements

O(log(n))

O(log(n))

O(1)

Linear (Brute Force)(线性查找-蛮力法)

Array

O(n)

O(n)

O(1)

Shortest path by Dijkstra,

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,
using an unsorted array as priority queue
(Dijkstra最短路径,使用无序数组作为优先队列)

Graph with |V| vertices and |E| edges

O(|V|^2)

O(|V|^2)

O(|V|)

Shortest path by Bellman-Ford(Bellman-Ford最短路径法)

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

Quicksort

(快速排序)

Array(数组)

O(n log(n))

O(n log(n))

O(n^2)

O(n)

Mergesort

(归并排序)

Array

O(n log(n))

O(n log(n))

O(n log(n))

O(n)

Heapsort

(堆排序)

Array

O(n log(n))

O(n log(n))

O(n log(n))

O(1)

Bubble Sort

(冒泡排序)

Array

O(n)

O(n^2)

O(n^2)

O(1)

Insertion Sort

(插入排序)

Array

O(n)

O(n^2)

O(n^2)

O(1)

Select Sort

(选择排序)

Array

O(n^2)

O(n^2)

O(n^2)

O(1)

Bucket Sort

(桶排序)

Array

O(n+k)

O(n+k)

O(n^2)

O(nk)

Radix Sort

(基数排序)

Array

O(nk)

O(nk)

O(nk)

O(n+k)

Heaps(堆)

Heaps

Time Complexity(时间复杂度)

 

Heapify

Find Max

Extract Max

Increase Key

Insert

Delete

Merge

 

Linked List (sorted)

(有序链表)

-

O(1)

O(1)

O(n)

O(n)

O(1)

O(m+n)

Linked List (unsorted)

(无序链表)

-

O(n)

O(n)

O(1)

O(1)

O(1)

O(1)

Binary Heap

(二叉堆)

O(n)

O(1)

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(m+n)

Binomial Heap

(多项式堆)

-

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(log(n))

Fibonacci Heap

(斐波那契堆)

-

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

Adjacency list

(邻接表)

O(|V|+|E|)

O(1)

O(1)

O(|V| + |E|)

O(|E|)

O(|V|)

Incidence list

(关联表)

O(|V|+|E|)

O(1)

O(1)

O(|E|)

O(|E|)

O(|E|)

Adjacency matrix

(邻接矩阵)

O(|V|^2)

O(|V|^2)

O(1)

O(|V|^2)

O(1)

O(1)

Incidence matrix

(关联矩阵)

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

 

Basic Array

(基本数组)

O(1)

O(n)

-

-

O(1)

O(n)

-

-

O(n)

Dynamic Array

(动态数组)

O(1)

O(n)

O(n)

O(n)

O(1)

O(n)

O(n)

O(n)

O(n)

Singly-Linked List

(单链表)

O(n)

O(n)

O(1)

O(1)

O(n)

O(n)

O(1)

O(1)

O(n)

Doubly-Linked List

(双链表)

O(n)

O(n)

O(1)

O(1)

O(n)

O(n)

O(1)

O(1)

O(n)

Skip List

(跳跃表)

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(n)

O(n)

O(n)

O(n)

O(n log(n))

Hash Table

(哈希表)

-

O(1)

O(1)

O(1)

-

O(n)

O(n)

O(n)

O(n)

Binary Search Tree

(二叉查找树)

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(n)

O(n)

O(n)

O(n)

O(n)

Cartesian Tree

(笛卡尔树)

-

O(log(n))

O(log(n))

O(log(n))

-

O(n)

O(n)

O(n)

O(n)

B-Tree

(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)

Red-Black Tree

(红黑树)

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)

Splay Tree

(伸展树)

-

O(log(n))

O(log(n))

O(log(n))

-

O(log(n))

O(log(n))

O(log(n))

O(n)

AVL Tree

(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

猜你喜欢

转载自blog.csdn.net/SCDN_CP/article/details/83827209