Atenţie! Aceasta este o versiune veche a paginii, scrisă la 2013-03-26 12:50:15.
Revizia anterioară   Revizia următoare  

Numbers everyone should know

Cosmin
Cosmin Negruseri
26 martie 2013

Jeff Dean , a famous Google engineer, popularized a list of latency numbers everyone should know. The list is a great resource for designing infrastructure system.

Algorithms and their complexity occur often in critical parts of computer systems, but I find that a lot of even experienced engineers don't have a good understanding about how a n log n algorithm compares to a n^5 one.

In the coding contest world competitors think of these tradeoffs all the time. No wonder, there's a set of numbers every algorithm designer should know.

The table below shows the limits that can be reached in a few seconds by algorithms of different complexities. I've also added a few examples of algorithms or problems and data structures that may occur in those complexity classes.

maximum n for a few seconds execution timecomplexityalgorithmsdata structures
8nnbrute force, cartesian product 
9-10n!brute force, backtracking, next_permutation 
13-173ndynamic programming with exponential stateshash_map (to store the states)
15 - 20n2 2ndynamic programming with exponential statesbitsets, hash_map
15 - 252nsubset enumeration, brute force, dynamic programming with exponential states 
25 - 403n/2, 2n/2meet in the middlehash tables (for set intersection)
30-50n4, n5, n6  
300-500n3all pairs shortest paths, largest sum submatrix, matrix multiplication, matrix chain multiplication, network flow 
1000 - 10000n2largest empty rectangle, Dijkstra, Prim (on dense graphs) 
30000n1.585, n sqrt nKaratsuba, square root tricktwo level tree
60000n log2 ndivide and conquer2d range trees
100000n log nsorting, divide and conquer, sweep line, Kruskal, Dijkstrasegment trees, range trees, heaps, treaps, binary indexed trees, suffix arrays
1000000n, n log log n, n log* nset intersection, Eratosthenes sieve, radix sort, KMP, topological sort, Euler tour, strongly connected components, 2satdisjoint sets, tries, hash_map, rolling hash
1000000000log n, sqrt nbinary search, ternary search, fast exponentiation, euclid algorithm 
Categorii: