There are two fundamental ways of measuring complexities
度量复杂性的基本方式有两种:
-
Complexity of algorithms
算法复杂性
- For an algorithm A, the (worst-case) time complexity of A is the maximum running time over all inputs x of length n.
- 对于一个算法A来说,A的(最差)时间复杂性是其对n长的输入x的最大的运行时间
-
Complexity of problems
问题复杂性
- For a computational problem, its time complexity is the time complexity of the optimal algorithm which solves the problem.
- 对于一个计算问题,它的时间复杂性是解决这一问题的最优算法的时间复杂性
The complexity of an algorithm tells how good the algorithm is, yet the complexity of a problems tells how hard the problem is. While the former is what we care mostly about in practice, the later is more about the fundamental truths of computation.
算法复杂性告诉我们一个算法有多么好,而问题复杂性则说明一个问题有多么困难。前者,我们关注的是其应用。后者,是其计算上的根本事实。
复杂性类
Definition 1: The class P is the class of decision problems that can be computed by polynomial time algorithms. |
Definition 2: The class NP consists of all decision problems f that have a polynomial time algorithm A such that for any input x,
|
Common misuses of the terminology:
- "This algorithm is NP." --- NP is a class of decision problems, not algorithms.
- "This problem is a NP problem, so it must be very hard." --- By definition, a problem is in NP if it's positive instances are poly-time verifiable, which implies nothing about the hardness. You probably means the problem is NP-hard.
- "NP problems are the hardest problems." --- There are infinitely many harder problems outside NP. Actually, according to a widely believed conjecture, there are infinitely many classes of problems which are harder than NP