![Alan Turing](static/img/alan-turing.jpg)
![Turing machine](static/img/turing-machine-2.png)
---
## Complexity classes
+ *P*: decision problems for which **polynomial-time** algorithms exist
("*tractable*")
+ **Most** of the algorithms in this course! \`O(n^c)\`
+ *EXP*: problems solvable in **exponential** time: \`O(2^(n^c))\`
+ *R*: problems solvable in **finite** time
+ R = "**recursive**" (Turing 1936, Church 1941)
![P, EXP, and R](static/img/P-EXP-R.svg)
---
## Examples
+ Does a weighted graph have a **net-negative cycle**?
+ In *P*: e.g., *Bellman-Ford* \`O(|V||E|) = O(n^2)\`
+ Given a **chess** board configuration (n x n), can White **win**?
+ In *EXP* (exhaustive search) but **not** in *P*
+ Given a **Tetris** board + seq of pieces, can you **survive**?
+ In *EXP* but not **known** whether in *P*
+ Given a computer **program** and **input**, does it **halt**?
+ Automated **infinite loop** checker
+ [Uncomputable](https://en.wikipedia.org/wiki/Halting_problem)! (∉ *R*)
+ **Cannot** solve in *finite* time for **all** programs, for **all** inputs
---
## Halting problem
+ Assume *Halt(P, s)* solves the **halting problem**:
+ Input two strings: a **program** *P* and an **input** *s* to *P*
+ Outputs *TRUE* ⇔ *P(s)* **halts**
+ Now, consider the following **program**:
```
def Koan( X ):
if Halt( X, X ):
loop forever
Koan( Koan )
```
+ Case 1: *Koan*( *Koan* ) **halts**.
+ ⇒ *Halt*( *Koan*, *Koan* ) = TRUE (by correctness of *Halt*)
+ ⇒ *Koan*( *Koan* ) loops forever (by code of *Koan*)
+ Case 2: *Koan*( *Koan* ) **doesn't** halt.
+ ⇒ *Halt*( *Koan*, *Koan* ) = FALSE (by correctness of *Halt*)
+ ⇒ *Koan*( *Koan* ) halts (by code of *Koan*)
---
## Outline for today
+ All-pairs shortest path
+ Johnson (reweighted Dijkstra): \`O(|V|^2 log |V| + |V| |E|)\`
+ Tractability
+ Complexity classes: *P*, *EXP*, *R*
+ **Non-deterministic verification:** *NP*
+ **NP-hard and NP-complete**
+ Semester review
---
## NP
+ **Certification** algorithm: instead of saying whether *s* ∈ *X*,
+ Check a proposed **proof** *t* that *s* ∈ *X*:
+ *C(s,t)* is a **certifier** for problem *X* if for every *s*:
+ *s* ∈ *X* ⇔ ∃ **certificate** *t* such that *C(s,t)* = TRUE
+ **NP** (nondeterministic polynomial): all problems *X*