Input Size VS Time Complexity

2018-05-01 11:10:54

This article introduces the relationship between the scale of input data and the upper limit of time complexity, and the type of algorithm to be used can be inferred from the scale of the data.

  • < 10: O(n!) permutation
  • < 15: O(2^n) combination
  • < 50: O(n^4) DP
  • < 200: O(n^3) DP, all pairs shortest path
  • < 1,000: O(n^2) DP, all pairs, dense graph
  • < 1,000,000: O(nlogn), sorting-based (greedy), heap, divide & conquer
  • < 1,000,000: O(n), DP, graph traversal / topological sorting (V+E), tree traversal
  • < INT_MAX: O(sqrt(n)), prime, square sum
  • < INT_MAX: O(logn), binary search
  • < INT_MAX: O(1) Math

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325079133&siteId=291194637