Time Complexity
[time-complexity]
Time Complexity [time-complexity]
Where is 3colormap? We know it is in EXP, and either in Np (complexity class) or in both NP and P.
The Time Hierarchy theorem tells us that there is something in EXP P. (why? still not clear)
NP and Time Complexity
[cpsc/NP-complexity]
NP and Time Complexity [cpsc/NP-complexity]
NP is very important! Contains a large about of natural problems.
- ex. Hamilton path, 3COLORGRAPH, graph isomorphism, satisfiable boolean formulas
Many problems in NP have “identical complexity”, i.e., are complete. (We’ll talk about this later.)
Definition 1. Runtime
[runtime]
Definition 1. Runtime [runtime]
-
- The runtime of a Turing machine is : . (the number of steps of on input until it halts) (assume is a decider for simplicity)
- The runtime of a nondeterministic Turing machine on input is max-length of any root-leaf path. For deciders – no infinite paths!
Recall:
Definition 2. TIME(t(n))
[TIME-tn]
Definition 2. TIME(t(n)) [TIME-tn]
is the class of all languages such that there exists a Turing machine with runtime that decides .
In briefer notation:
Definition 1. P (complexity class)
[P]
Definition 1. P (complexity class) [P]
Why is P a good definition for efficient computation?
- Insensitive to model of computation: by the extended Church-Turing thesis, switching computational models “only” involves a polynomial slowdown
- Closed under composition: can use polynomial time algorithm as a subroutine
- In practice: algorithms usually can be improved. If we find an time algorithm, it typically can be improved to, say, time.
Example. 2COLORMAP
Let be a “map” of countries in the plane, where a coloring is valid if neighboring countries have different colors.
Question. The two color map does not work for every map. So consider it as a problem: . Is 2COLORMAP P?
Answer. Yes! Start with an arbitrary country, set it to red, set their neighbors to blue, and continue. If there is a conflict, reject, if there is no conflict, accept.
It’s unknown if the three color map is in P. It’s known to be in EXP:
Definition 3. NTIME(t(n))
[NTIME-tn]
Definition 3. NTIME(t(n)) [NTIME-tn]
NTIME(𝑡(𝑛))={language𝐿:∃NTM𝑀thatdecides𝐿in time𝑂(𝑡(𝑛))}
NP (complexity class)
[cpsc/NP]
NP (complexity class) [cpsc/NP]
Let’s prove that 3colormap is in NP.
Proof: Design a nondeterministic Turing machine to decide 3colormap in polynomial time.
- Iterate through vertices
- Nondetermistically pick a color for each vertex (a “lucky guess”)
- Check all pairs of neighbors to see if they are the same color
- If so reject, otherwise accept