Marginal

Theory of Computation

What can be computed, and at what cost: finite automata and regular languages, Turing machines and the Church–Turing thesis, the halting problem and reductions, Kolmogorov complexity, time complexity, P, NP and NP-completeness, PSPACE, randomized algorithms, interactive proofs, one-time pads and pseudorandomness.

31 lessons in 4 units

Start your free trial14 days free. No card needed.
What you'll learn

31 lessons, one small step at a time

Each lesson states its goal, then works up to it in short steps with practice after each. A placement test at the start skips what you already know.

Automata & Turing Machines

8 lessons
  1. Running a DFARun a deterministic finite automaton on an input string, and design its states to remember what a task needs.
  2. Finite automataCount the strings of a given length that a DFA accepts, and tell which tasks finite memory can and cannot do.
  3. NondeterminismRun a nondeterministic automaton by tracking its set of possible states, bound the size of the equivalent DFA, and explain when that bound is reached.
  4. Limits of finite automataFind the fewest states a DFA needs by counting distinguishable prefixes, and prove that some languages need more than finite memory.
  5. Context-free grammarsGenerate strings with a context-free grammar, tell when a grammar is ambiguous, count nested structures, and match languages with the machines that recognize them.
  6. Running a Turing machineRun a Turing machine step by step, and count the steps it takes on an input.
  7. Turing machinesCount a Turing machine's configurations to decide halting on a bounded tape, explain why the unbounded tape changes this, and design a simple machine.
  8. The Church–Turing thesisExplain what a universal Turing machine does and why all reasonable models compute the same functions, and count Turing machines.

Computability

6 lessons
  1. The halting problemProve that no program decides the halting problem, and tell which questions about programs it makes unsolvable.
  2. DiagonalizationBuild the diagonal sequence missing from a list, tell countable sets from uncountable ones, and construct a set no program decides.
  3. Mapping reductionsGet the direction of a reduction right, and build a reduction from the halting problem.
  4. Rice's theoremApply Rice's theorem to tell which questions about programs are undecidable, and explain how practical verification lives with it.
  5. Short descriptionsBound the Kolmogorov complexity of a string from above by exhibiting a program, including for strings built from repeated patterns.
  6. IncompressibilityCount programs to show that most strings cannot be compressed, and prove that Kolmogorov complexity is uncomputable.

Complexity

8 lessons
  1. Time budgetsDefine running time and the class P, and find the largest input a polynomial or an exponential algorithm can handle within a budget of steps.
  2. Hardware vs. algorithmsCompute how much larger an input a faster computer lets polynomial and exponential algorithms handle, and explain why better algorithms matter more.
  3. Checking certificatesCheck certificates for subset sum and for satisfiability, and explain what puts a problem in NP.
  4. P and NPCompute the cost of brute-force search, and explain what would follow from P = NP.
  5. Polynomial reductionsTurn vertex covers into independent sets and cliques into independent sets, and explain what a polynomial-time reduction shows.
  6. NP-completenessProve a problem NP-complete by reduction, classify problems, and describe how NP-hard problems are handled in practice.
  7. Games & quantifiersEvaluate alternating quantifiers as moves in a game, explain why such games appear harder than NP, and compute the minimax value of a game.
  8. PSPACECount the memory and the work of a recursive game evaluator, and place PSPACE among the complexity classes.

Randomness, Interaction & Cryptography

9 lessons
  1. One-sided errorCompute the error of a repeated one-sided randomized test, and the number of runs needed for a target error.
  2. Amplifying by majority voteCompute the error of a majority vote over repeated runs, and bound it for many runs with the Hoeffding bound.
  3. Catching a cheating proverCompute a cheating prover's chance of passing the graph non-isomorphism protocol, and the number of rounds needed to catch it.
  4. Interactive proofsDefine the completeness and soundness of an interactive proof, and explain how debate lets a limited judge check stronger systems.
  5. XOR encryptionEncrypt and decrypt with XOR, explain why a one-time pad hides everything about the message, and show what a reused key leaks.
  6. Perfect secrecyCompute the key length perfect secrecy requires, and explain what perfect secrecy does and does not guarantee.
  7. Distinguishing advantageCompute the distinguishing advantage of a test, including the exhaustive test, and explain why security is defined against efficient tests only.
  8. PseudorandomnessCompute how small a fraction of strings a pseudorandom generator can output, and explain where pseudorandom generators come from.
  9. Public-key cryptographyCompute modular powers, run a Diffie–Hellman key exchange, and explain what public-key security rests on.
Sample lesson

Running a DFA

Goal: Run a deterministic finite automaton on an input string, and design its states to remember what a task needs.

Vending machines, traffic lights, text-search engines and the lexers inside every compiler are finite automata: machines with a fixed, finite memory that react to one input symbol at a time. They are the simplest model of computation, and the starting point for asking what more powerful machines can do.

We will follow states and transitions and finish with the memory in the state.

Step 1: States and transitions

A deterministic finite automaton (DFA) has finitely many states and a fixed transition rule: from each state, each symbol leads to exactly one next state. Run it by starting in the start state and applying the transition for each symbol in turn; it accepts if it ends in an accepting state. Example: a DFA with states A and B, where a keeps the state and b switches it, tracks whether it has read an even or odd number of bs. On abba it goes A, A, B, A, A: the state changes twice, and it ends in A.

Step 2: Memory in the state

A DFA's only memory is its current state, so designing one means deciding what to remember. To check divisibility of a binary number by 3, remember the value mod 3 read so far: reading bit b doubles the value and adds b, so

r ← (2r + b) mod 3
011001012

The three states are the possible remainders. Reading 1011 (eleven) visits 0 → 1 → 2 → 2 → 2, and 11 mod 3 = 2. The same idea works for any modulus: tracking mod 5, from state 2 the bit 1 leads to (4 + 1) mod 5 = 0.

In the app, each step ends with practice questions, new ones every time, and the lesson comes back later in spaced reviews.

Start Theory of Computation

Lessons that need something you haven't learned yet bring it in first, from any course.

Start your free trial14 days free. No card needed.