Lecturers: Hans-Joachim Böckenhauer (organisation), Dennis Komm (content)
Course text: J. Hromkovič, Theoretische Informatik, 5. Auflage (Springer Vieweg). The lecture follows it almost 1:1. The English edition has reduced scope.
Covered: Lecture 1 (15.09., slides 1–38), Lecture 2 (18.09., slides 1–29 plus handwritten part: start of Hromkovič Ch. 2, “Alphabete, Wörter, Sprachen”)
Course organisation (Lecture 1, Böckenhauer)
- Lectures: Tue + Fri, 08:00–10:00, HG E 7. In the first week there was also a stream to HG E 5, which will stop.
- Moodle holds everything: forum (use it instead of e-mail, so everyone gets the same information), exercise sheets, solutions, quizzes, enrolment in exercise groups.
- Exercise groups: Tue/Wed/Thu afternoons, about 17–18 groups, including one English group per day. Enrolment opened 15.09. at 12:00, for about one week. The first sessions were in week 2.
- Written homework: a weekly sheet (1–2 tasks), uploaded Friday after the lecture, due one week later via Moodle. You may submit in teams of up to 3, and should then join the same exercise group. Sheets are corrected and graded, and model solutions follow a week later.
- Moodle quiz: weekly, done individually, auto-graded. Open from Friday noon until roughly Monday evening or Tuesday noon, before the next exercise session. The content is exam-relevant and the points count toward admission.
- Worked examples: about every 2nd–3rd week. A video explains something not covered in the lecture, and you solve a similar task in the exercise group. These are not graded and not needed for midterm admission, but the content is exam material.
- Two voluntary midterms (Zwischenprüfungen): around 5–10 Nov and early/mid Dec, probably Mon or Fri 16–18. Exact dates were not yet fixed.
- Admission requires 50 % of the homework + quiz points accumulated up to each midterm.
- The average grade of both midterms can be adopted as the final grade, by signing a form at the end of the semester. In that case you skip the session exam.
- Stay registered for the session exam in myStudies anyway. Otherwise the grade cannot be entered.
- Historical pass rate is about 80 %.
- The session exam is in Jan/Feb.
- All materials are also in English.
1. Executive Overview & Core Objectives
The course asks two questions:
- Computability (Berechenbarkeit): what can a computer provably never do, in any model, language or future technology?
- Complexity (Komplexität): of what can be computed, how efficiently (time, space)?
Week 1 is a fast “trailer” (explicitly not the normal pace). Cantor’s diagonalisation, Turing’s undecidability argument, P vs. NP and polynomial-time reductions are previewed and will be done formally later. The handwritten part of Lecture 2 then starts the formal foundations: alphabets, words and the operations on words (Hromkovič §2.2).
Learning objectives. After this week you should be able to:
- define gleich groß, abzählbar, überabzählbar, and give explicit bijections and ;
- reproduce Cantor’s diagonal proof that is uncountable, including the subtlety;
- explain why a precise mathematical definition of “problem” and “algorithm” is needed;
- define a decision problem (Entscheidungsproblem) as a language and model PRIM, TSP/HC, CLIQUE and IND-SET this way;
- state the Church–Turing thesis and its contrapositive;
- reproduce the diagonal argument showing DIAG is undecidable;
- explain why the halting problem is hard intuitively (the Goldbach program);
- define -notation, P, polynomial-time verifier, NP and NP-completeness;
- explain why , and why “NP = not polynomial” is wrong;
- carry out and prove correct the reduction CLIQUE → IND-SET;
- use the Ch. 2 vocabulary precisely: , , , , , , Nummer, Bin, concatenation, reversal, iteration, Teilwort/Präfix/Suffix, canonical order.
2. Core Concepts & Formal Definitions
2.1 Historical frame: from Leibniz to Turing
| Who | What | Point for us |
|---|---|---|
| Leibniz (1646–1716) | “Calculemus!” (Lassen Sie uns rechnen): every question could eventually be settled by calculation | The dream that everything is computable |
| Russell (1872–1970) | Russell’s paradox (Russellsche Antinomie) | Naive set theory is contradictory |
| Hilbert (1862–1943) | Hilbert’s program: a system of axioms in which every true statement is provable and no contradiction arises | Wants consistency and completeness |
| Russell & Whitehead | Principia Mathematica (1910–13): an attempt at a contradiction-free foundation | — |
| Gödel (1906–1978) | Incompleteness theorem (Unvollständigkeitssatz, 1931): if a (sufficiently strong) system is consistent, there are true statements it cannot prove | Mathematics is and remains incomplete |
| Turing (1912–1954) | 1936: formal definition of algorithm (Turing machine) plus problems no algorithm solves | Birth of CS as a science |
| Church (1903–1995) | Church–Turing thesis | TM = “algorithm” |
Exam Trap: errors in the sources
- Slide 12 gives Gödel’s dates as “1862–1943”. Those are Hilbert’s dates. Gödel lived 1906–1978.
- The lecturer says Church was Turing’s doctoral student. It is the other way round: Turing did his PhD under Church (Princeton, 1938).
- The order “Hilbert, then Russell–Whitehead” is loose. Principia (1910–13) predates Hilbert’s program in its formalised form (1920s). The exam will not test this, but don’t reproduce the wrong order.
2.2 Sizes of infinite sets
Definition (gleich groß / equal size)
Two sets and are equally large (gleich groß), written , if there is a bijection (Bijektion) . That is, the elements can be paired one-to-one with nothing left over on either side.
This also applies to infinite sets, and that is where intuition fails. Removing an element, or “doubling” a set, need not change its size.
Definition (abzählbar / countable)
An infinite set is countable (abzählbar) if , i.e. there is a bijection . Equivalently, every element of gets a unique natural-number “index”, so can be listed as
An infinite set that is not countable is uncountable (überabzählbar).
Convention: (includes 0), , , .
Facts stated in Lecture 1 (slides 17–21)
- , although intuitively “should” be smaller
- is countable, although intuitively
- and are countable, although this looks like “infinity × infinity”
- Satz: is not countable (überabzählbar). It even suffices to look at .
Exam Trap: "abzählbar" for finite sets
The slide defines abzählbar only for infinite sets. Many textbooks call a set countable if it is finite or in bijection with . Check which convention the book uses before relying on it in a proof.
2.3 What is a problem? (informal preview, Lecture 1)
Definition (Alphabet, Wort — preview version)
An alphabet (Alphabet) is a finite, non-empty set of symbols. A word (Wort) is a finite string of symbols from the alphabet.
Example: (the digits, not the decimal numbers). is a word over . It can be interpreted as the number 13 817, but first and foremost it is just a string.
Definition (Entscheidungsproblem / decision problem)
Given a set of words, the decision problem for is: for a given word , decide whether . The answer is always JA or NEIN.
Sets of words are called languages (Sprachen). Interesting languages are usually infinite, although each of their words is finite.
The modelling looks trivial (yes/no) but is very general. The whole of computability and complexity theory can be built on it. Results transfer to search problems (Suchprobleme), e.g. actually outputting a clique instead of just saying “yes”.
Examples:
- . Asking “is prime?” is the same as asking “is ?”. .
- . Graphs are encoded e.g. as adjacency matrices (Adjazenzmatrix): a 0/1 string, plus delimiters if needed. A Hamiltonian cycle (Hamiltonkreis) is a cycle that visits every vertex exactly once and returns to the start. A graph with a vertex of degree 1 can never have one.
Exam Trap: "TSP" on the slides is really the Hamiltonian-cycle problem
The slides call the language of graphs with a Hamiltonian cycle “TSP”. Strictly, that is the Hamiltonian cycle problem (HC). The real Traveling Salesperson Problem works on weighted complete graphs and asks for a tour of minimum (or at most ) cost. In a formal exam answer, use the definition the task gives you.
2.4 What is an algorithm?
The Wikipedia-style definition (“an unambiguous procedure for solving a problem or class of problems, consisting of finitely many well-defined single steps”) is not a mathematical object:
- What counts as a “single step” (Einzelschritt)? Multiplication? Bitwise addition? A memory jump?
- Under this definition, recipes, directions and user manuals are also “algorithms”.
- Without a formal definition you cannot prove limits. Someone can always say “my notion of algorithm can do more”.
Turing’s idealised human computer (Turing 1936, On Computable Numbers, with an Application to the Entscheidungsproblem; Turing was about 24). A mathematician has:
- a pen that never runs out,
- unboundedly much squared paper,
- a finite set of rules (arithmetic, logic, …), never makes mistakes and never tires.
Procedure:
- Input: a word on the paper.
- Loop: look at the symbol under the pen; depending on it and the internal rules, possibly overwrite it and move the pen one cell left or right; repeat.
- Termination: eventually she is done; she halts (hält).
- Output: the word now on the paper.
Abstraction: 2D paper becomes a one-dimensional tape (Band); the rules become a finite control (endliche Kontrolle) with states (Zustände); the pen position becomes the read/write head (Lese-/Schreibkopf). This is the Turing machine (TM). It will be defined formally later.
Church–Turing-These (Church–Turing thesis)
Turing machines can compute exactly what algorithms can compute (“effectively computable”, effektiv berechenbar).
Contrapositive (the important direction): what a TM cannot compute, no algorithm can compute: not in Java, C++, Ruby on Rails or Python, not with quantum computers, randomised or genetic algorithms, neural networks or LLMs.
Intuition: why the thesis is a thesis, not a theorem
“Effectively computable” is an informal notion, so it cannot be proved equivalent to a formal one. The evidence: every reasonable model of computation ever proposed (real computers, quantum computers, transformers, …) can be simulated by a TM. Exotic ideas such as “throw a computer into a black hole to get infinite time” are not reasonable models.
2.5 Undecidability
Satz von Turing (Turing's theorem)
There are decision problems that cannot be solved by any TM, and hence (by Church–Turing) by no algorithm. Such problems are called undecidable (unentscheidbar).
Core idea: there are only countably many TMs/algorithms, but uncountably many problems. The concrete witness is the language (proof in §3.5).
Definition (DIAG, informal version from the lecture)
Enumerate all TMs and all words over a fixed alphabet
Halting problem (Halteproblem), preview: given source code (in any language), decide whether it terminates. This is closely related to DIAG and is proved undecidable later.
2.6 Running time and efficiency
Running time is measured as a function of the input length (Eingabelänge), not as absolute seconds. “Is 5 prime?” is easy, but “is 10 000 000 013 prime?” should take longer for any method, since you at least have to read the input.
Exam Trap: input length, not input value
For PRIM, the input is given in binary (or decimal) with digits. Without leading zeros, , so . An algorithm that is linear in the value is therefore exponential in the length .
(The transcript says “from to ”; the correct range is .)
Definition ( -Notation)
For functions :
Informally: for large , grows at most a constant factor faster than . is a set of functions.
Slide examples: , , , , , .
Growth table (slide 18.09., p. 5):
| 10 | 50 | 100 | 300 | 10 000 | |
|---|---|---|---|---|---|
| 400 | 10 000 | 40 000 | 360 000 | 400 000 000 | |
| 1 000 | 125 000 | 1 000 000 | 27 000 000 | 13 digits | |
| 1 024 | 16 digits | 31 digits | 91 digits | 3 011 digits | |
| 59 049 | 24 digits | 48 digits | 143 digits | 4 772 digits |
These von Cobham und Edmonds (Cobham–Edmonds thesis)
Efficient algorithms are those that run in polynomial time: running time in for some constant .
and are efficient; is not.
(The transcript spells the names “Coppern” and “Koppel”; the correct name is Alan Cobham.)
Why “some polynomial” and not a fixed degree?
- Robustness: if a “real” algorithm (x86, smartphone, …) solves a problem in , a TM solves it in for some possibly larger constant , and vice versa. Polynomial time does not depend on the model; a fixed exponent would.
- Empirical: once some polynomial algorithm is found for a natural problem, the exponent usually gets pushed down to something reasonable (e.g. primality testing).
- Even is eventually far smaller than .
Definition (Klasse P)
P is the class of all decision problems that can be solved by a TM in polynomial time (“efficiently”).
We say class rather than set to avoid the “sets of sets” issues from Russell.
Examples in P: minimum spanning tree (Kruskal, Prim from A&D) and PRIM (“PRIMES is in P”, Agrawal–Kayal–Saxena 2002, which grew out of undergraduate work).
Exam Trap: PRIM is in P, but the naive tests are not polynomial
Both trial-division tests from the slides (§4.2) are exponential in . PRIM P needs the much cleverer AKS algorithm. The lecturer recalled the original exponent as about , later reduced towards . In the literature as I know it, the original proven bound is , improved to (Lenstra–Pomerance). Either way: polynomial.
Running time always means worst case. For even inputs both naive prime tests stop immediately; the worst case is a prime input.
2.7 Polynomial-time verifiers and NP
Definition (Polynomzeit-Verifizierer, PV — informal)
A polynomial-time verifier does not have to compute the answer itself. Along with the input it receives a string , a (potential) witness (Zeuge/Zeugin):
- if is a JA-instance, there exists a witness that proves it, and the PV then answers JA;
- if is a NEIN-instance, the witness can be arbitrary nonsense, and the PV must answer NEIN for every witness.
The PV must run in polynomial time in . Implicitly, this means the witness must also have polynomial length.
Example (Hamiltonian cycle): a TM gets the graph and must decide whether a Hamiltonian cycle exists; no efficient method is known. A PV gets the graph plus a witness such as and only checks it: every vertex appears exactly once, the cycle closes, and every consecutive pair is an edge. This is efficient.
Definition (Klasse NP)
NP is the class of all decision problems that can be solved efficiently by a PV.
“N” stands for nichtdeterministisch (nondeterministic). PVs are an equivalent reformulation of polynomial-time nondeterministic TMs, which come later.
Exam Trap: NP does NOT mean "not polynomial"
NP = Nondeterministic Polynomial time. NP is not “the hard problems”. Every problem in P is also in NP. NP is the superclass of P within which we still have hope of finding polynomial algorithms. The lecturer said he would be “personally hurt” if you leave the course thinking NP = “nicht polynomiell”.
Satz: (proof in §3.6)
Consequences:
- If a problem is outside NP (not even efficiently verifiable), it is certainly not efficiently solvable.
- P vs. NP: is or ? Open. Most researchers believe . It is one of the Millennium Prize Problems (USD 1 000 000). It could even be unprovable (compare Gödel).
- Sad fact: for no problem in NP can we prove a superlinear lower bound for general TMs. Only is known (you have to read the input).
2.8 NP-completeness and reductions
Definition (NP-vollständig — informal version from the lecture)
A problem is NP-complete (NP-vollständig) if the efficient solvability of implies the efficient solvability of all problems in NP.
So if an efficient TM is ever found for one NP-complete problem, then . If one is ever proved to have no polynomial algorithm, then .
Satz von Cook (Cook's theorem, 1971)
There exists an NP-complete decision problem: SAT (Boolean satisfiability).
Karp (1972)
There are 21 further NP-complete problems. Today thousands are known (TSP/HC, CLIQUE, IND-SET, graph colouring, …), and for none can we prove that no efficient TM exists.
Exam Trap: dates
The transcript says a mathematician “came in 1972” and showed the existence of an NP-complete problem, and later “Cook in ‘72”. Cook’s theorem is 1971 (Levin independently); Karp’s 21 problems are 1972.
Definition (Clique, Independent Set)
Let be an undirected, unweighted graph.
- is a clique (Clique) if all vertices of are pairwise connected: .
- is an independent set (unabhängige Menge) if no two vertices of are connected: .
is part of the input, not a fixed constant.
Definition (Polynomzeit-Reduktion — informal)
We reduce problem to problem by showing: if could be solved efficiently, then could be solved efficiently too. Concretely, build an efficient algorithm for that uses a hypothetical efficient algorithm for as a black box. Intuitively, is then at least as hard as .
Recipe for proving NP-complete:
- Show .
- Pick an already known to be NP-complete.
- Reduce to .
- Conclude by transitivity: efficient ⇒ efficient ⇒ efficient everything in NP.
Believed picture (slide 18.09., p. 26): P and the NP-complete problems are disjoint subclasses inside NP. If , they all collapse.
2.9 Formal foundations: alphabets and words (Hromkovič §2.2, handwritten part of Lecture 2)
Definition (Alphabet)
An alphabet (Alphabet) is any finite, non-empty set. Its elements are called letters/symbols (Buchstaben, Symbole). Usually denoted , which is not a sum sign.
Examples:
- (Boolean alphabet). For computability you can almost always restrict to it.
- (lower-case Latin letters)
- (keyboard symbols); Unicode or ASCII, or subsets of them
- ( as a placeholder for variables)
Definition (Wort, Länge, leeres Wort, , )
Let be an alphabet.
- A word over (Wort über ) is a finite sequence of symbols from . It is written without commas or brackets, e.g. over , although formally it is a tuple.
- The length (Länge) of a word is the number of positions in , e.g. .
- The empty word (leeres Wort) is the unique word of length 0. Other books write ; this course uses .
- is the set of all words over (Kleene star, as in regular expressions).
- is the set of all non-empty words. The book writes set difference with a minus sign.
Exam Trap: length counts positions, not distinct symbols
, although only 2 distinct symbols occur.
Also: is a word, is a language with one element, and is the language with no elements. So .
In Lecture 2 the lecturer said ” would be the same without ”. He misspoke: the set without is .
Definition (Nummer and Bin: numbers as words)
For (each ), is interpreted as a binary number:
The least significant bit is on the right: gets weight , gets . For the empty sum gives 0; this case is not of practical interest here.
Conversely, for , is the binary representation of without leading zeros (the shortest one). Additionally .
Intuition: Nummer and Bin are not inverse bijections
always holds. But is not injective: . picks the canonical representative.
Words are just strings. The problem determines their interpretation: a number, an adjacency matrix, a formula, …
Definition (Verkettung / Konkatenation)
For an alphabet , the concatenation is the map
i.e. is written directly after . The dot is usually omitted.
Example: , , so .
is neutral: and . Concatenation is associative but not commutative (). Hence is a monoid; this remark is from the book, not stated in the lecture. .
Definition (Umkehrung / reversal)
For with , the reversal (Umkehrung) of is
Example: . Also .
Definition (Iteration)
For and , the -th iteration of is defined recursively:
The book writes ; both are equal by associativity.
Example : , , , , …
Iteration is also used on single letters inside words: . Careful: the exponent applies only to the symbol directly before it (see §4.5).
Definition (Teilwort, Präfix, Suffix)
Let .
- is a subword (Teilwort, also Infix) of if : .
- is a prefix (Präfix) of if : .
- is a suffix (Suffix) of if : .
Lecture convention: is a proper (echtes) subword if additionally and .
Naming convention (not always kept): letters ; words . The lecturer names the trailing piece (as in the book), even though a student suggested .
Exam Trap: "proper" has several conventions
The lecture’s version of echt () is stricter than the common convention "" (often also ""). Under the lecture’s version, a prefix is not automatically a proper subword, because there . In exams, use the definition the task gives; if none is given, use the book’s.
Also: is a prefix, suffix and subword of every word, and is a prefix, suffix and subword of itself.
Definition ( )
For and , denotes the number of occurrences (Anzahl der Vorkommen) of the letter in .
Example: , , and .
Definition (kanonische Ordnung / canonical order)
Let be an alphabet with an order on its letters. The canonical order on is: for ,
In words: first by length, then lexicographically at the first differing position. The common prefix may be .
Example: (common prefix , then ). Over :
Exam Trap: canonical order ≠ dictionary order
Pure lexicographic (dictionary) order on would put . Infinitely many words come before , so it does not enumerate as a list . Sorting by length first fixes this: there are only finitely many () words of each length . This is exactly why the canonical order is used to enumerate words in diagonal arguments.
3. Step-by-Step Derivations & Mathematical Proofs
3.1 Russell’s paradox (Lecture 1, slides 8–9)
Define , the set of all sets that do not contain themselves. Example from the lecture: does not contain itself, so . A set that (hypothetically) contains itself would not be in .
Question: is ? There are only two possibilities.
- Assume . Then is a set containing itself. But contains exactly the sets that do not contain themselves. So . Contradiction.
- Assume . Then is a set that does not contain itself, so by definition of , . Contradiction.
Both cases are contradictory, so naive set formation (“every property defines a set”) is inconsistent. This is the same structure as Pinocchio saying “My nose will grow now” (it grows iff he lies): if the statement is true, he lied, so it is false; if it is false, he lied, so the nose grows and it is true.
Intuition: the common pattern behind Russell, Gödel, Cantor and Turing
Each argument builds an object that talks about itself in a negated way (“the set of sets that do not contain themselves”, “the word is in DIAG iff does not accept ”, “the number differing from the -th number in the -th digit”). This self-reference with negation is diagonalisation.
3.2 Explicit bijections (slides 17–19)
: . It is injective, and every odd has the preimage . ( is even.)
: . Inverse for . Removing one element from an infinite set does not change its size.
(as described in the lecture): map 0 to 0, positive to “double minus 1”, negative to “double with the other sign”:
Check against slide 19 (read as : ): , , , . ✓
Why bijective: positive integers go bijectively onto the odd naturals (), negative integers go bijectively onto the even naturals (), and . These three images partition .
is countable (stated, not proved, in the lecture; standard proof added here). Write all fractions , , in an infinite grid (row , column ). Walk the anti-diagonals , each of which is finite, and skip fractions not in lowest terms (, …). Every positive rational appears exactly once, at a finite position, which gives a bijection with . This is Cantor’s first diagonal method. For , interleave , positives and negatives exactly as for .
3.3 is uncountable: Cantor’s diagonal argument (slides 21–23)
Satz
is uncountable. It suffices to show that is uncountable.
Proof by contradiction (Widerspruchsbeweis): assume the opposite, derive something absurd (“pigs can fly”), conclude the assumption was false.
- Assumption: is countable, so there is a list containing every real number in . The slides number from 0 and use “digit of row ” with an index shift; the idea is identical.
- Write each in decimal: Irrational numbers have infinite expansions. That is no problem: the table was already infinite downwards, and now it is infinite to the right as well.
- Construct from the diagonal:
so for all . Then , and is uniquely determined by the table even though we cannot write it down completely. - is not in the list: suppose for some . In position , , so and differ in the -th digit.
- Why differing in a digit really means a different number (the periodicity issue the lecturer postponed): decimal expansions are not unique, e.g. A differing digit alone could therefore be fooled. Our uses only digits 4 and 5, never 0 or 9, so has a unique expansion. If , every expansion of would equal ‘s unique expansion, which differs from row at digit . Contradiction.
- Since was arbitrary, is in no row. So the list is incomplete, contradicting step 1. ∎
Slide example: the diagonal digits are and the slide chooses (, , , ). Any choice works, as long as it avoids the 0/9 problem.
The method is called diagonalisation (Diagonalisierung), more precisely Cantor’s second diagonal method. (The slide’s “Widerspruch Diagonalisierung” is a typesetting artefact.)
3.4 Countably many algorithms, uncountably many problems (lecture’s high-level claim, made precise)
This was claimed in the lecture; the precise version follows later in the course.
- TMs are countable: every TM has a finite description over a fixed finite alphabet. Mapping each TM to its description is injective into . is countable: list it in canonical order, which works because there are finitely many words of each length. So TMs can be listed (the “Gödelisierung”/encoding of TMs comes later).
- Languages are uncountable: a problem is a language . Suppose all languages were listed and the words in canonical order. Define . Then for every , because they disagree on . This is §3.3 with “digit” replaced by “membership”.
- Conclusion: there are more languages than TMs, so some language has no TM.
3.5 DIAG is undecidable (slides 34–37)
Setup: list all TMs and all words (e.g. binary words in canonical order: ). Build an infinite table whose cell is J if answers JA on and N otherwise.
Example: if happened to be the PRIM machine, its row would read N on 0, N on 1, J on 2, J on 3, N on 4, J on 5, …
Definition: the diagonal entry is N, i.e. does not answer JA on . Slide example: diagonal J, N, N, J, … gives .
Claim: no TM decides DIAG.
Proof by contradiction:
- Assume a TM decides DIAG: it answers JA exactly on the words of DIAG.
- is a TM, so it appears in the list: for some (e.g. the 325 000th).
- Look at cell :
- Case J: answers JA on . By definition of DIAG, . But decides DIAG, so it must answer NEIN on . Contradiction.
- Case N: answers NEIN on . By definition, . But then , being correct for DIAG, must answer JA. Contradiction.
- Both cases are impossible, so no such exists. DIAG is undecidable. ∎
Exam Trap: TMs need not halt
The lecture’s table assumes each TM answers J or N on every word. Real TMs may run forever. The formal version (later) reads “N” as “does not accept” (rejects or never halts): . The argument still works. If you write “rejects” instead of “does not accept” in a formal proof, it becomes subtly wrong.
Intuition: why care about such an artificial language?
DIAG is constructed specifically to be undecidable, so it seems esoteric. But it is the starting point: via reductions, undecidability of DIAG transfers to natural problems such as the halting problem, which we would very much like to solve (compilers, verification).
3.6
Let , decided by a TM in time . Build a PV : on input , ignore and run on .
- If , any witness (e.g. ) leads to JA.
- If , answers NEIN for every .
runs in polynomial time, so . ∎ (A PV gets the same problem plus extra information, so it can only be at least as capable.)
3.7 Why a reduction transfers NP-completeness (slide 21)
Let with NP-complete.
- NP-complete means: an efficient algorithm for gives an efficient algorithm for every .
- The reduction shows: an efficient algorithm for gives an efficient algorithm for .
- By chaining: an efficient algorithm for gives an efficient algorithm for , hence for every . Together with , is NP-complete. ∎
The direction matters: reduce the known-hard problem to the new one (“my problem is at least as hard as yours, because solving mine solves yours for free”).
3.8 Reduction CLIQUE → IND-SET with correctness proof
Complement graph: for let with . Delete existing edges and insert edges exactly where there were none. Same vertex set, no self-loops.
Lemma
is a clique in is an independent set in .
The middle equivalence holds because for , exactly one of and is true.
Reduction algorithm (slide 25): given a hypothetical efficient TM for IND-SET, the following decides CLIQUE:
- Input .
- Compute : flip every off-diagonal entry of the adjacency matrix.
- Run on with the same , and output its answer.
Correctness: has a -clique (Lemma) has an independent set of size answers JA.
Efficiency: with , step 2 touches entries, so it is linear in the input length . The output has the same size . If runs in , the whole algorithm runs in , which is polynomial.
Membership: IND-SET . The witness is a set of vertices; check and the pairs against the matrix in polynomial time. So: if CLIQUE is NP-complete, IND-SET is NP-complete.
Converse: the same construction reduces IND-SET to CLIQUE (since ). Both problems are equally hard in this sense.
Exam Trap: the reduction must be efficient AND produce small output
A reduction is only useful if (a) the transformation itself runs in polynomial time and (b) its output has polynomial size. Otherwise plugging it into a polynomial black box need not give polynomial total time.
3.9 Running time of the naive prime tests (slides 18.09., p. 6)
Input with bits, so .
- Test 1 (try every divisor ): for a prime (the worst case) the loop runs times, so the time is .
- Test 2 (try divisors up to ): this is enough by the following lemma.
Lemma
If is composite, has a nontrivial divisor with .
Proof. with . If then , so . Contradiction. ∎
Iterations . This is much better than , but still exponential. The plots on slides 8–9 show and both shooting “vertically” upward, while and stay flat. The first plot’s axis range was deliberately chosen so that looks harmless.
Exam Trap: an exponential with a "small base" is still exponential
for every . Exponentials with base dominate every polynomial.
4. Worked Examples & Applications
4.1 The Goldbach program: why the halting problem is not “just read the code” (slide 38)
Three programs: print("Hello, world."); exit() clearly halts. while True: i = 1 (followed by unreachable prints) clearly never halts, ignoring hardware failure and memory limits. Now the interesting one, from the slide:
n = 4 # Initialisierung
p = 1
while True:
p = p + 1
if isprime(p):
q = n - p
if isprime(q): # p und q sind prim und n = p + q
print(n + "=" + p + "+" + q)
n = n + 2
p = 1
if p > n/2: # Keine Primzahlen p und q mit n = p + q gefunden
exit()Trace:
- : is prime, is prime. Print “4=2+2”, then , .
- : , (not prime). , (prime). Print “6=3+3”, then .
- : , no; , yes. Print, then . And so on.
What it does: for it searches for primes with also prime. It halts iff it finds an even that is not a sum of two primes.
Goldbach conjecture (Goldbach-Vermutung): every even integer is the sum of two primes. It is open, though checked by computer to very large bounds. The program halts Goldbach is false.
So even with perfect understanding of these 12 lines, we cannot say whether the program terminates without settling an open conjecture. This is not a proof of undecidability, only a teaser that “inspect the code carefully (with Copilot)” cannot work in general.
Exam Trap: details in the slide code
- The transcript says “even numbers greater than 4”. Goldbach is about even numbers (equivalently ).
- As literal Python,
n + "=" + praises aTypeError(int + str). It is pseudocode in Python syntax. Correct would beprint(f"{n}={p}+{q}").
4.2 The two prime tests (slides 18.09., p. 6)
# Test 1: alle Teiler 2..zahl-1
test = 2
while test < zahl:
rest = zahl % test
if rest == 0:
print("Nein"); exit(0)
test = test + 1
print("Ja"); exit(0)# Test 2: nur bis zur Wurzel
test = 2
wurzel_zahl = sqrt(zahl)
while test <= wurzel_zahl:
rest = zahl % test
if rest == 0:
print("Nein"); exit(0)
test = test + 1
print("Ja"); exit(0)Example: zahl = 97 (prime, bits since )
- Test 1: tests , i.e. 95 iterations, no divisor found, so “Ja”. Compare .
- Test 2: , tests , i.e. 8 iterations, so “Ja”. Compare .
- For zahl = 98 (even) both stop after 1 iteration. Worst case is a prime.
4.3 Verifier for the Hamiltonian-cycle problem (slide 18.09., p. 15)
Input: a graph on . Witness: .
Verification steps, each polynomial:
- First vertex = last vertex? ✓
- Do the inner vertices contain each of the 6 vertices exactly once? ✓
- Is each consecutive pair an edge, i.e. adjacency entry 1 for , , , , , ? If all ✓, answer JA.
If the graph had no Hamiltonian cycle, any witness must fail one check. For example, if , check 3 fails and the PV answers NEIN. This is correct, because for a JA-instance a correct witness would have been supplied.
Cost: checks for vertices, each an matrix lookup (on a TM: polynomial).
4.4 The live Python demo of the reduction (Lecture 2, after the break)
The lecturer coded the reduction live to show that the “black box” picture is just ordinary program composition. Cleaned-up version:
def solve_independent_set(G, k):
"""Black box: assumed to decide IND-SET in polynomial time (we don't know how)."""
...
def solve_clique(G, k):
n = len(G) # G: adjacency matrix (list of lists of 0/1)
H = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if i != j: # keep the diagonal at 0: no self-loops
H[i][j] = 1 - G[i][j] # complement every off-diagonal entry
return solve_independent_set(H, k) # same kExam Trap: the diagonal of the adjacency matrix
In the live demo the lecturer flipped every entry, including the diagonal, and said “on the diagonal there should actually only be ones”. That is a slip. For simple graphs the diagonal is 0 (no loops), and the complement must keep it 0, hence the
i != jabove. The lecturer acknowledged he was being sloppy.
Example: does = single edge between two vertices have a clique of size 2?
, . The complement is (no edges). is an independent set of size 2 in , so the black box returns
True. Indeed is a 2-clique (an edge) in . The demo printedTrue.
4.5 Word operations (handwritten part, Lecture 2)
Example: in-lecture questions
- .
- Q: what is for ? A: . Likewise , , .
- Q: what is ? A (student): .
- Q: natural recursive definition of ? A (student): .
- ; .
- .
- ; ; ; .
- Canonical order: .
Exam Trap: precedence of iteration
means , not . The exponent binds only to the immediately preceding symbol unless brackets are used.
4.6 Student questions
Student question (Lecture 2): are there decidable problems that provably cannot be solved in polynomial time?
Yes. There is a large hierarchy of complexity classes above P (the time hierarchy theorem gives decidable problems requiring exponential time). This comes later. What is open is whether such a problem lies inside NP: no problem in NP is known to be outside P.
Clarification (Lecture 2): "But sorting has an lower bound!"
The bound from A&D holds for comparison-based sorting, a restricted model (Radix sort and Bucket sort are not comparison-based). For general TMs we cannot prove any bound above for NP problems, i.e. not even , although we believe many need about .
Question during the break: how do reductions work for harder problem pairs?
CLIQUE ↔ IND-SET is the simplest case (just complement). For other pairs the reductions can be very intricate. They are done in detail later in the course.
5. Intuition & Conceptual Bridges
Intuition: why counting proves impossibility
Each algorithm is a finite text, so there are countably many. Each problem is an arbitrary subset of , so there are uncountably many. Most problems therefore have no algorithm. Diagonalisation makes this concrete by constructing one such problem (DIAG). It is the same move as constructing a real number missing from any list.
Intuition: the existence vs. non-existence asymmetry
To show a problem is in P, you show one algorithm and verify it (e.g. Kruskal for MST). To show it is not in P, you would have to rule out all algorithms ever. “I found none, nor did anyone else” is weak evidence, but it is roughly the best we have. NP-completeness turns this weakness into a strong structural statement: “if you crack this one, you crack thousands at once, and many brilliant people have failed”.
Intuition: why the strange verifier model?
No real computer gets the answer whispered to it. The PV model is a thought tool: it defines the largest natural class (NP) where we cannot yet rule out efficient algorithms. Checking a solution seems easier than finding it, and P vs. NP asks whether that intuition is provably true.
Intuition: MST vs. Hamiltonian cycle
A spanning tree through all vertices (easy, in P) and a cycle through all vertices (HC, NP-complete) look almost the same. Yet one is efficiently solvable and the other believed not to be. Small changes in a problem can cause huge jumps in complexity.
Connections to prior courses:
- Diskrete Mathematik: bijections, countability, Cantor, proof by contradiction, possibly Gödel numbering.
- Algorithmen und Datenstrukturen: -notation, worst-case analysis, MST (Kruskal/Prim), the comparison-based sorting lower bound.
Where the course goes next (slide 18.09., p. 28):
- Finite automata (endliche Automaten) and regular languages (reguläre Sprachen), closely related to regular expressions (that is where the Kleene star comes from). They are strongly restricted TMs, so concepts such as nondeterminism are easy to study there first.
- Gradually more general models, up to formal Turing machines.
- Computability: encoding TMs as words (Gödelisierung), formal DIAG, the halting problem, reductions for undecidability.
- Complexity: formal P, NP (nondeterministic TMs and verifiers), polynomial-time reductions, Cook’s theorem (SAT), NP-completeness proofs.
The Ch. 2 vocabulary (, , , , concatenation, iteration, canonical order, Nummer/Bin) is used constantly from now on. Canonical order is exactly what enumerates in DIAG.
6. Summary & Self-Assessment Questions
Cheat table
| Concept | Key statement |
|---|---|
| gleich groß | iff there is a bijection |
| abzählbar | (infinite) with ; are countable |
| überabzählbar | , , the set of all languages |
| Diagonalisation | build an object that differs from the -th listed object at position |
| Church–Turing thesis | TM = algorithm; not TM-computable means not computable at all |
| DIAG | iff does not accept ; undecidable |
| iff | |
| Efficient | polynomial time (Cobham–Edmonds) |
| P | decision problems solvable by a TM in polynomial time |
| NP | decision problems solvable by a polynomial-time verifier (nondeterministic polynomial) |
| Known relations | ; ? open; believed |
| NP-complete | , and efficient implies all of NP efficient |
| Cook 1971 / Karp 1972 | SAT is NP-complete / 21 more NP-complete problems |
| Reduction | efficient implies efficient ; reduce from known-hard to new |
| CLIQUE → IND-SET | , cost |
| Alphabet | finite, non-empty set |
| , | all words; all non-empty words () |
| empty word, , neutral for concatenation | |
| binary of without leading zeros; | |
| , | |
| Teilwort/Präfix/Suffix | / / |
| number of occurrences of in | |
| Canonical order | by length first, then lexicographically at the first differing position |
Self-assessment questions
Question 1. Give the bijection from the lecture. Compute and , and find and . Prove that is a bijection.
Solution to Question 1
, for , for .
- , .
- is odd, so it comes from a positive with , i.e. : .
- is even and , so it comes from a negative with , i.e. : .
Injective: the three cases map into the pairwise disjoint sets , the odd numbers, and the even numbers . Within a case the map is affine with nonzero slope, hence injective.
Surjective: ; odd gives with ; even gives . ∎
Question 2. In Cantor’s proof, why does the lecture (and the book) need to “be careful with periodicity”? Construct a list for which the naive rule "" produces a number that is in the list.
Solution to Question 2
Some reals have two decimal expansions: The diagonal argument proves only that differs from row as a digit string. If the two strings are different expansions of the same real, could still be in the list.
Counterexample to the naive rule. We want to appear in the list in its other form
- Rule . To get we need ; to get for we need .
- Let (so ), and choose as any listing of reals whose -th digit is 9 (such expansions are easy to choose).
- Then . So is in the list, and the argument breaks.
Fix: use only digits that cannot create double expansions, e.g. if , else . Then has a unique expansion and the contradiction is valid.
Question 3. Prove carefully that DIAG is undecidable. State where the proof uses that DIAG talks about the diagonal, and why the answer “N” must be read as “does not accept”.
Solution to Question 3
Enumerate the TMs (possible because each has a finite description, so there are countably many). Enumerate the words in canonical order.
.Suppose a TM decides DIAG. Then for some . Consider , the word on the diagonal position ; this is where the definition of DIAG refers to itself.
- If accepts , then by definition. But decides DIAG, so it must not accept . Contradiction.
- If does not accept , then . Since decides DIAG, it accepts . Contradiction.
So no TM decides DIAG. ∎
Why “does not accept”: a TM can reject or loop forever. If DIAG were defined as ” rejects ”, looping machines would fall outside both cases and the case split would not be exhaustive. “Accepts / does not accept” is a true dichotomy.
Question 4. True or false? Justify each.
(a) NP is the class of problems that cannot be solved in polynomial time.
(b) If IND-SET , then , assuming CLIQUE is NP-complete.
(c) To show a new problem is NP-hard, reduce to a known NP-complete problem .
(d) For TSP/HC we know a lower bound of for general TMs.
Solution to Question 4
(a) False. NP = nondeterministic polynomial time. , so NP contains all efficiently solvable problems. Whether NP contains problems outside P is exactly the open P vs. NP question.
(b) True. CLIQUE reduces to IND-SET via in polynomial time. A polynomial algorithm for IND-SET therefore gives one for CLIQUE. Since CLIQUE is NP-complete, this gives one for every problem in NP, so , and with we get .
(c) False (wrong direction). Reducing to only shows “efficient implies efficient ”, i.e. is no harder than . You must reduce the known-hard to .
(d) False. For general TMs, no lower bound above the trivial (read the input) is known for any problem in NP. Lower bounds like for sorting hold only in restricted models (comparison-based).
Question 5. Let with , , .
(a) Compute , , , .
(b) List all prefixes and all suffixes of . Is a subword? Is it proper in the lecture’s sense?
(c) Sort canonically: .
(d) Compute , , and explain why .
Solution to Question 5
(a)
- , so (a palindrome).
- .
- . Count of : positions 1, 3, 5, 8, so . Length (check: ).
(b) Prefixes of : . Suffixes: .
is a subword: with , . Since and , it is a proper subword in the lecture’s sense.(c) By length first: length 0: ; length 1: ; length 2: (lexicographic: at position 2, and at position 1); length 3: .
Result: .(d)
- .
- , so .
- , because removes leading zeros. is not injective (all of map to 5), so is only a right inverse: , but .