Time Complexity
Still in preparation. Please check the references at the end of the document.
Time Complexity
Even though a language may be decidable, it may not be feasible to compute it in practice, if the solution requires too many computational resources (such as storage space, time, etc.). Today we will study one kind of computational resource: time. To define the time complexity of a problem, we first need to define the running time of a (single-tape) Turing machine.
The time cost of a Turing machine
Now that we have defined the time cost of a Turing machine, we can define its time complexity.
Definition 1: The (worst-case) time complexity of a (single-tape) Turing machine
Now that we have defined the time complexity of a Turing machine, we can define the time complexity of a language.
Definition 2: Let
From the above definition, we have a number of natural complexity classes:
Time Complexity Class | Definition |
---|---|
Constant time | |
Linear time | |
Quasi-linear time | |
Quadradic time | |
Polynomial time | |
Linear-exponential time | |
Exponential time | |
Double-exponential time |
Observations
Time complexity classes can be defined in terms of other models of computation, such as multi-tape Turing machines, or other models that we have not discussed. Depending on the choice of computational model, the time complexity classes may change. However, the choice of model does not affect the time complexity classes in a significant way.
For instance, if we wanted to define time complexity classes in terms of multi-tape Turing machines, one can show that the time complexity classes that arise are equivalent up to a polynomial factor. This is captured by the following proposition, whose proof can be found in [S13, Theorem 7.8].
Proposition 1: For any function
Time Hierarchy Theorem
Now that we have defined time complexity classes, it is natural to ask: are these classes distinct from one another? In other words, does giving more time to a Turing machine allow it to solve more problems? As we will now see, the answer is yes. But before we do so, we need one more definition.
Definition 3: A function
Examples of time-constructible functions:
Theorem 1:
Proof idea: we will use the fact that the universal Turing machine can be efficiently implemented (i.e., with small overhead) to simulate other Turing machines. With this at hand, together with the observation from last lecture of the principle that a Turing machine cannot predict the behavior of another Turing machine without simulating it, we can prove the theorem.
Proof: Consider the following language:
On input
:
- Let
. - Compute
(which is possible as is time-constructible) and store it in a binary counter. We will decrement this counter every time we execute a basic instruction of in step 4. If the counter ever reaches zero, reject. - If
is not of the form , reject. - Simulate (using the universal Turing machine)
on . - If
accepts , accept. If rejects , reject.
It suffices to show that
- Since
is time-constructible, we can implement the binary counter in time on its tape. - Checking if
is of the form can be done in time. - Now, let us analyze the simulation of
on input .- Each step of
can be simulated in time, as the description of has length . - Since
runs for at most steps (since we will always halt in case has not decided in steps), the total time to simulate on input is .
- Each step of
- Step 5 can be done in
time.
Thus,
Now, to finish the proof of the theorem, we need to show that
Consider the following Turing machine
On input
:
- Let
. - If
is not of the form , reject. - Run
on input , and do the opposite. That is, if accepts, reject. If rejects, accept.
By construction,
By being more careful with the implementation of each step in the above argument (as well as the implementation of the universal Turing machine), one can show the following improved version of the Time Hierarchy Theorem. A proof can be found in [S13, Theorem 9.10].
Theorem 2 (Full Time Hierarchy Theorem): For any two functions
The proof of the above theorem follows the same ideas as the proof of Theorem 1, but with a more careful implementation of the universal Turing machine.
Polynomial Time
Acknowledgements & References
This lecture was based on these resources:
- Lecture notes by Prof. Eric Blais.
- [S13, Sections 7.1, 7.2, 9.1]