Skip to content


Welcome to Week 9!

This week we learn about two important classes of problems: P and NP.

Learning Objectives for this week

  • Define the running time / time complexity of a DTMs and NDTMs.
  • Use big-O notation to express orders of growth of functions.
  • Show time bounds on multi-tape TMs and NDTMs simulated by DTMs.
  • Define the class P and NP.
  • Analyse the cost of an algorithm using big-O notation.
  • Design and analyse verification for NP problems.
  • Explain the P vs NP question.

Pre-class Activity

Visit the GeoGebra or Desmos website (or any other similar platform) and try plotting/drawing the following functions in turn:

\[ x, x^2, x^3, \; 2^x, 3^x, \; x!, x^x. \]

Can you see the difference? Is it easy to tell them apart from each other?

Another approach that helps tell which one has a faster growth rate is to look at these relative to each other. We can plot their ratio, e.g. to see if \(x^2\) grows faster or \(2^x\) we plot the ratio \(x^2/2^x\): if the values get smaller than that means that the denominator \(2^x\) is relatively much larger than the numerator \(x^2\), and vice versa.

Try the pairs

\[ x^2, x^3\quad x^2, 2^x\quad x^3, 2^x\quad 2^x, 3^x\quad 2^x, x^x\quad x^x, x!\quad \]

Lecture videos

The PDF slides are available for download below.

Download Slides

Time complexity

We saw last week that the fundamental question of "whether all computational problems are decidable" has a negative answer: there are many computational that cannot be decided.

From this week onwards, we concentrate on the next question: "When the problem is decidable; how much does it cost to decide?" We are mainly interested in the the time we would have to wait for, and secondarily the space (storage) required for the computation.

[This is lecture 8, not 9. Please excuse the mistake in the recording.]

Big-O notation

We can, if we really work hard, quantify the exact number of operations that a specific TM takes to decide a problem. But we would have to redo the work for any small changes in the details. One convenient tool that we use the capture the main and leading term in the expression giving the count of steps is known as big-O notation.

The P and NP classes

We are now ready to define two main time-complexity classes, according to whether the TM is deterministic or non-deterministic.

We only concentrate on the polynomial cost functions because anything higher is considered inefficient.

NP Certificates

There is an insightful and powerful characterisation of the class NP through the use of certificates that can be verified in polynomial time using a DTM.

Ready for the lab exercises?

Attempt Lab 9 exercises

Ask & Answer Questions

Don't forget: you can use Teams or the Aula's feed to raise questions for me and the rest of the class.

Add your questions to the Community Feed and take a look at others' questions. If you see a question which you'd like to answer then just go ahead and participate in the discussion!