Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lecture 7

In-class notes: CS 505 Spring 2025 Lecture 7

Diagonalization

Suppose we are given complexity classes and . How can we show they are different? That is, show .

We’ve seen the technique of diagonalization before when we showed undecidability of certain languages. Diagonalization is a general technique that gives us one way of showing the above result: differentiating between complexity classes. Intuitively, if we are given and , diagonalization allows us to differentiate between and as follows.

  • If decides , then we want to say is different from any decider for .
  • We do this by arguing for any , if then , and vice versa.

Origins of Diagonalization

Diagonalization was originally introduced by Georg Cantor. He used diagonalization to prove that . That is, the set of all natural numbers is strictly smaller than the set of all real numbers. This result at the time was not well received: these are both infinite sets, how could you possibly reason about them being different sizes?

This proof first relies on defining when two infinite-sized sets are the same size. Briefly, two sets of infinite size are said to have the same size if there exists a bijection from to . That is, for every , there is a unique such that .

For example, we know that via the following bijection.

Under this definition of set equality, Cantor showed that . We’ll do an easier proof by showing is smaller than the entire interval of real numbers .

Theorem. .

Proof. We do a proof by contradiction. Suppose that . This means there is a bijection from to . We can write the bijection as an infinite table.

From this table, we’ll construct a new real number that is not in the above bijection. We construct the real number digit by digit. We’ll index digits in the right column of the table starting with (i.e., the first digit after the decimal point is the 0-th digit). Let denote the bijection described by the table.

Then, for each , we define for any such that . That is, the -th digit of will be explicit different from the -th digit of the real number . As a picture, we look at the digits in the table on the diagonal.

Taking the positions on the diagonal, we construct the new real number . Now, there does not exist any such that . This is because for every , we have , which implies that . Thus, the mapping cannot exist.

Time Hierarchies

With diagonalization fleshed out more, we can now discuss time hierarchies.

Deterministic Time Hierarchy

First, we’ll show a time hierarchy theorem for deterministic computations.

Theorem. Let and be time constructible functions such that . Then .

As a corollary of the above theorem, we have:

Corollary. There exists a language decidable in time but not decidable in time for any time constructible function .

We now prove the time hierarchy theorem.

Proof. As you might expect from the preceding discussion, we’ll have a diagonalization proof. First, we build a deterministic Turing machine as follows.

For any and for any , does the following.

  1. Compute .
  2. Simulate .
  3. If halts within steps, output .
  4. Else output .

Note that step (1) can be done in time since is time constructible. If runs in time , then step (2) runs in time since we can do universal simulation with only logarithmic overhead.

Now, let denote the language of ; i.e., . By definition, decides Moreover, since only simulates for at most steps.

Claim. .

This is where our diagonalization comes into play. Suppose this claim is not true. This implies , and there is a decider deciding in time .

Now, consider running . Suppose that . Then, simulates for at most steps. Notice that runs in time on any input. In particular, runs in time . By universal simulation, we know that simulates in time . Since we have that halts in at most steps. So, for large enough ,1 runs for less than steps. Moreover, by universal simulation, still runs in at most steps on this input.

This implies that completes the simulation of and outputs . However, this implies that . We assumed that decides the language , which also decides by definition, but these two machines differ on this input. This is a contradiction, so does not exist.

We have two important corollaries from the time hierarchy theorem.

Corollary. For all , we have .

Corollary. .

Non-deterministic Time Hierarchy

Now, we move on to show the non-deterministic time hierarchy theorem.

Theorem. Let be time constructible functions such that . Then, .

Proof. Unfortunately, we cannot do a standard diagonalization here. With the deterministic time hierarchy, we simulated the machine (which shouldn’t have existed), and were able to flip its output. The simulation was deterministic and always output the opposite of the machine . However, with non-deterministic simulation, there could be exponentially many outputs on a single input. Recall that a non-deterministic decider needs to only output accept on at least one computation path, and reject on all (when rejecting a string).

The idea behind the non-deterministic simulation will be to do a lazy simulation. In particular, our diagonalization will only differ on a single output; for all other outputs, we will output the correct bit (of the machine we are simulating). This will be enough to derive our contradiction.

We proceed with the proof. Let and let denote the machine described by . Now let be a function such that , , and . Let be any function such that .

Build a non-deterministic Turing machine which does the following. takes as inputs strings of the form for any , where denotes the string of 1’s.

  1. Compute such that .
  2. If :
    1. Non-deterministically simulate for at most steps.
    2. If halts within steps, output .
    3. Else output .
  3. If :
    1. Deterministically simulate by trying all computation paths.
    2. Output .

Now, we argue that runs in time . First, step (1) takes at most time. Second, all of step (2) only takes time. Third, step (3.1) takes at most time, which overall takes time. Therefore, runs in time .

Let . By the above discussion, we know that .

Claim. .

Again, suppose this is not the case. Then there is an NTM which decides in at most time. Let be large enough such that for satisfying , we have .

Now, run . If , then simulates for at most steps. By construction, , and runs in non-deterministic time . So the simulation halts before steps and .

This implies the following equalities.

Moreover, by assumption, and both decide the same language . This implies for all , we have This actually shows that for all ; similarly, the same is true for : for all .

Now suppose that . By construction, now simulates deterministically and outputs . Here, outputs if there exists an accepting path, and outputs otherwise. This implies that . But this is a contradiction since above we established that for all . Thus, cannot exist.


  1. Recall that every Turing machine has an infinite number of equivalent strings which describe said machine.