每个程序员都应该知道的14个数字(关于算法运行时间的)

本文列举了不同算法复杂度对应的可接受输入规模,并针对各种常见算法和数据结构进行了详细说明,为开发者提供设计算法时的重要参考。

14 numbers every developer should know列举了14个数字,可以作为大家设计算法时的一个参考。下表列出了秒数量级下各种算法复杂度能接受的输入个数。

maximum n

complexity

algorithms

data structures

1,000,000,000 and higher

log n, sqrt n

binary search, ternary search, fast exponentiation, euclid algorithm

 

10,000,000

n, n log log n, n log* n

set intersection, Eratosthenes sieve, radix sort, KMP, topological sort, Euler tour, strongly connected components, 2sat

disjoint sets, tries, hash_map, rolling hash deque

1,000,000

n log n

sorting, divide and conquer, sweep line, Kruskal, Dijkstra

segment trees, range trees, heaps, treaps, binary indexed trees, suffix arrays

100,000

n log2 n

divide and conquer

2d range trees

50,000

n1.585, n sqrt n

Karatsuba, square root trick

two level tree

1000 - 10,000

n2

largest empty rectangle, Dijkstra, Prim (on dense graphs)

 

300-500

n3

all pairs shortest paths, largest sum submatrix, naive matrix multiplication, matrix chain multiplication, gaussian elimination, network flow

 

30-50

n4, n5, n6

  

25 - 40

3n/2, 2n/2

meet in the middle

hash tables (for set intersection)

15 - 24

2n

subset enumeration, brute force, dynamic programming with exponential states

 

15 - 20

n2 2n

dynamic programming with exponential states

bitsets, hash_map

13-17

3n

dynamic programming with exponential states

hash_map (to store the states)

11

n!

brute force, backtracking, next_permutation

 

8

nn

brute force, cartesian product

 

转载于:https://www.cnblogs.com/fresky/archive/2013/05/01/3053155.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值