Unit 0

Mathematical and Algorithmic Prerequisites

The proof, asymptotic, graph, probability, and machine-model tools used throughout complexity theory.

Goals

  • Read asymptotic claims with their quantifiers and hidden constants exposed.
  • Measure an instance by the length of its encoding, not by the value it represents.
  • select and write direct, inductive, contradictory, diagonal, and counting proofs.
  • Use finite probability spaces, conditional probability, expectation, and union bounds safely.

1. What complexity measures

Complexity theory asks how many resources are sufficient or necessary as the input grows. The variable is normally the encoding length n=∣x∣n=|x|. If the mathematical input is the integer NN, its binary representation has length ⌊log⁡2N⌋+1\lfloor\log_2 N\rfloor+1, whereas its unary representation has length NN. Thus an algorithm taking O(N)O(N) steps is exponential in the binary input length but linear in the unary length. Encoding is not clerical detail: it determines the question.

A decision problem is represented by a language L⊆Σ∗L\subseteq\Sigma^*. A decider MM must halt on every input and satisfy

x∈L⟹M(x)=1,x∉L⟹M(x)=0.x\in L\Longrightarrow M(x)=1,\qquad x\notin L\Longrightarrow M(x)=0.

An algorithm is the abstract method; a machine model specifies which operations count as one step. Later lessons use Turing machines so that “time” and “space” have precise meanings. Robust complexity classes tolerate reasonable simulation overhead, but an analysis must still name its model and encoding.

2. Sets, strings, functions, and graphs

For an alphabet Σ\Sigma, Σ∗\Sigma^* contains all finite strings, including the empty string ε\varepsilon. Concatenation is written xyxy, and ∣x∣|x| is length. A tuple needs a uniquely decodable encoding such as ⟨x,y⟩\langle x,y\rangle; merely writing xyxy can be ambiguous. A function f:N→Nf:\mathbb N\to\mathbb N is increasing if a≤ba\le b implies f(a)≤f(b)f(a)\le f(b), and it is unbounded if every constant is eventually exceeded.

A graph G=(V,E)G=(V,E) may be encoded by an adjacency matrix using Θ(∣V∣2)\Theta(|V|^2) bits or by an edge list using O((∣V∣+∣E∣)log⁡∣V∣)O((|V|+|E|)\log |V|) bits under a standard vertex-numbering convention. A polynomial-time claim under one reasonable graph encoding usually transfers to another only after proving a polynomial relation between encoding lengths.

Worked encoding example. Suppose an algorithm enumerates all integers from 00 through NN. It takes Θ(N)\Theta(N) iterations. On input 1N1^N this is linear. On the binary encoding of NN, whose length is n=Θ(log⁡N)n=\Theta(\log N), it takes 2Θ(n)2^{\Theta(n)} iterations. The code did not change; the complexity statement did.

3. Asymptotic notation with quantifiers

For eventually nonnegative functions,

f=O(g)  ⟺  ∃c>0 ∃n0 ∀n≥n0: f(n)≤cg(n),f=Ω(g)  ⟺  g=O(f),f=Θ(g)  ⟺  f=O(g) and f=Ω(g),f=o(g)  ⟺  ∀c>0 ∃n0 ∀n≥n0: f(n)<cg(n).\begin{aligned} f=O(g)&\iff \exists c>0\ \exists n_0\ \forall n\ge n_0:\ f(n)\le c g(n),\\ f=\Omega(g)&\iff g=O(f),\\ f=\Theta(g)&\iff f=O(g)\text{ and }f=\Omega(g),\\ f=o(g)&\iff \forall c>0\ \exists n_0\ \forall n\ge n_0:\ f(n)<c g(n). \end{aligned}

Big-OO is an eventual upper bound, not equality. Small-oo is strict asymptotic domination. For example, n2=o(n3)n^2=o(n^3), but 3n2≠o(n2)3n^2\not=o(n^2).

Claim. 4n2+3n+9=Θ(n2)4n^2+3n+9=\Theta(n^2).

Upper bound. For n≥1n\ge1, 3n≤3n23n\le3n^2 and 9≤9n29\le9n^2, so 4n2+3n+9≤16n24n^2+3n+9\le16n^2. Choose c=16,n0=1c=16,n_0=1.

Lower bound. For every nn, 4n2+3n+9≥4n24n^2+3n+9\ge4n^2. Choose c′=4,n0′=1c'=4,n_0'=1. Both quantified witnesses are required.

Useful growth facts include

log⁡n=o(nϵ),na=o(nb) (a<b),nk=2o(n),2n=o(2n2).\log n=o(n^\epsilon),\qquad n^a=o(n^b)\ (a<b),\qquad n^k=2^{o(n)},\qquad 2^n=o(2^{n^2}).

Changing a logarithm's constant base changes it by a constant factor. Moving a constant into an exponent is different: 2cn2^{cn} and 2n2^n are generally not within a constant multiplicative factor.

Guided construction

Growth-rate map

Step 1 of 6
Growth-rate comparisonCurves for log n, n, n log n, n squared, and two to the n on a linear vertical scale.01,0242,0483,0724,09624681012input size nfunction value (linear scale)log₂ n
log₂ n

Use the visualization by choosing an input size and comparing the same functions on linear and logarithmic vertical scales. The order is asymptotic; crossings at small nn do not invalidate it.

4. Proof methods

Direct proof and construction

To prove A⊆BA\subseteq B, begin with an arbitrary x∈Ax\in A and derive x∈Bx\in B. To prove membership in a complexity class, construct one machine meeting both correctness and resource bounds. A slow alternative algorithm does not disprove membership because class membership is existential.

Contrapositive and contradiction

The contrapositive of P⇒QP\Rightarrow Q is ¬Q⇒¬P\neg Q\Rightarrow\neg P and is logically equivalent. A contradiction proof assumes the negation of the desired statement and derives an impossibility. Always state what was negated: negating ∀x ∃y R(x,y)\forall x\,\exists y\,R(x,y) yields ∃x ∀y ¬R(x,y)\exists x\,\forall y\,\neg R(x,y).

Induction

For a statement P(n)P(n), prove a base case and then P(n)⇒P(n+1)P(n)\Rightarrow P(n+1). Strong induction may assume all earlier cases. In machine simulations, the invariant often says: “after ii simulated steps, the encoding represents exactly the simulated machine's configuration after ii steps.” The base case verifies the initial encoding; the step verifies one transition.

Counting and pigeonhole

If mm objects are placed in fewer than mm boxes, one box gets at least two objects. Complexity proofs count strings, machines, circuits, or configurations. For example, there are 2n2^n binary strings of length nn but 22n2^{2^n} Boolean functions on nn bits. This enormous gap underlies many existence arguments, though counting alone may not identify an explicit hard function.

Diagonalization

Given an enumeration M1,M2,…M_1,M_2,\ldots, define an object that differs from MiM_i on the iith designated input. The hard part is not the slogan “do the opposite”; it is ensuring that the diagonal simulator fits its resource budget and halts. Hierarchy theorems therefore require constructibility and a sufficient asymptotic gap.

5. Probability toolkit

A finite probability space consists of outcomes Ω\Omega and a distribution with total mass 11. An event is a subset of Ω\Omega. Conditional probability is

Pr⁡[A∣B]=Pr⁡[A∩B]Pr⁡[B](Pr⁡[B]>0).\Pr[A\mid B]=\frac{\Pr[A\cap B]}{\Pr[B]}\quad(\Pr[B]>0).

Events A,BA,B are independent when Pr⁡[A∩B]=Pr⁡[A]Pr⁡[B]\Pr[A\cap B]=\Pr[A]\Pr[B]. Pairwise independence does not imply mutual independence.

The union bound requires no independence:

Pr⁡[⋃i=1mAi]≤∑i=1mPr⁡[Ai].\Pr\left[\bigcup_{i=1}^m A_i\right]\le\sum_{i=1}^m\Pr[A_i].

If kk independent trials each fail with probability 2/32/3, the probability all fail is (2/3)k(2/3)^k. Independence is essential for multiplication.

For a random variable XX, linearity of expectation says

E ⁣[∑iXi]=∑iE[Xi]\mathbb E\!\left[\sum_i X_i\right]=\sum_i\mathbb E[X_i]

even when the XiX_i are dependent. With indicator IiI_i for event AiA_i, E[Ii]=Pr⁡[Ai]\mathbb E[I_i]=\Pr[A_i]. Thus if XX counts successful trials, its expectation is the sum of their success probabilities.

Example: amplification. Suppose an independent run succeeds with probability at least 2/32/3. Run it kk times and accept if any run succeeds when false acceptance is impossible. Failure requires every run to fail, so it is at most (1/3)k(1/3)^k. For two-sided error with majority vote, a concentration bound is needed; simply writing (1/3)k(1/3)^k would be wrong.

“With high probability” normally means probability at least 1−1/nc1-1/n^c for some fixed c>0c>0, or another explicitly stated bound approaching 11. It does not merely mean probability greater than 1/21/2.

6. Reading and writing formal claims

Quantifier order records dependence. In

∀M ∃cM>0 ∀x: TM(x)≤2cMSM(x),\forall M\ \exists c_M>0\ \forall x:\ T_M(x)\le 2^{c_M S_M(x)},

the constant may depend on MM but not on xx. Replacing it by ∃c ∀M ∀x\exists c\,\forall M\,\forall x asserts one universal constant and is much stronger. Before manipulating a proof, annotate every constant with what it may depend on.

For a language-class claim, separate three obligations:

  1. Semantics: the machine accepts exactly the intended strings.
  2. Termination: every required computation halts.
  3. Resources: the bound holds for every input of the given length, including no-instances.

Worst-case time is a maximum over inputs of length nn, not an average and not the time on a convenient example.

Common mistakes

  • Hiding a constant that actually depends on the input.
  • Measuring a number by its value instead of its bit length.
  • Reversing an implication when only its contrapositive is valid.
  • Multiplying probabilities without independence.
  • Proving correctness only for yes-instances or resource use only on accepting runs.
  • Treating O(f)O(f) as a function rather than a set of eventual bounds.
  • Assuming “polynomial” means practical for every exponent and constant.

Exercises

Exercise 1 — Prove Θ\Theta

Prove from the definition that 2n3+100n2=Θ(n3)2n^3+100n^2=\Theta(n^3). Exhibit explicit constants and n0n_0 in each direction.

Solution

Claim. 2n3+100n2=Θ(n3)2n^3+100n^2=\Theta(n^3).

Upper bound (OO). For n≥1n\ge1, 100n2≤100n3100n^2\le100n^3, hence

2n3+100n2≤2n3+100n3=102n3.2n^3+100n^2\le2n^3+100n^3=102n^3.

Take c=102c=102 and n0=1n_0=1.

Lower bound (Ω\Omega). For every n≥1n\ge1, 2n3+100n2≥2n32n^3+100n^2\ge2n^3. Take c′=2c'=2 and n0′=1n_0'=1.

Thus f=O(n3)f=O(n^3) and f=Ω(n3)f=\Omega(n^3), so f=Θ(n3)f=\Theta(n^3). Constants need not be optimal; they must be positive and uniform for all sufficiently large nn.

Exercise 2 — Refute OO

Prove that the claim 2n=O(n100)2^n=O(n^{100}) is false. Write the negation of the OO definition and complete it.

Solution

Negation of OO. The claim 2n=O(n100)2^n=O(n^{100}) means

∃c>0 ∃n0 ∀n≥n0: 2n≤c n100.\exists c>0\ \exists n_0\ \forall n\ge n_0:\ 2^n\le c\,n^{100}.

Its negation is

∀c>0 ∀n0 ∃n≥n0: 2n>c n100.\forall c>0\ \forall n_0\ \exists n\ge n_0:\ 2^n>c\,n^{100}.

Proof. Since lim⁡n→∞2n/n100=∞\lim_{n\to\infty}2^n/n^{100}=\infty, for every c,n0c,n_0 there exists n≥n0n\ge n_0 with 2n/n100>c2^n/n^{100}>c.

What this is not. Checking a few small values is not a proof: the definition concerns eventual behavior.

Exercise 3 — Unary versus binary encoding

Let AA be the language of unary inputs 1N1^N, and let BB be the language of binary encodings of the same integers. An algorithm counts from 00 to NN in Θ(N)\Theta(N) steps. Prove that it runs in linear time in the input length on inputs from AA, but exponential time in the input length on inputs from BB. Explain why there is no contradiction.

Solution

On x=1Nx=1^N we have ∣x∣=N|x|=N and Θ(N)=Θ(∣x∣)\Theta(N)=\Theta(|x|) steps — linear time.

On a binary encoding of NN of length n=⌊log⁡2N⌋+1=Θ(log⁡N)n=\lfloor\log_2 N\rfloor+1=\Theta(\log N), the step count is Θ(N)=2Θ(n)\Theta(N)=2^{\Theta(n)} — exponential in the input length.

There is no contradiction: the same program is measured against different input lengths. Encoding is part of the problem, so the complexity classification depends on it.

Exercise 4 — Union bound without independence

We sample kk values; for each ii, the probability that value ii is bad is at most 1/n21/n^2. Prove that the probability that at least one value is bad is at most k/n2k/n^2, without assuming independence. Deduce the case k=nk=n. Explain why one may not multiply success probabilities without an extra hypothesis.

Solution

Let AiA_i be the event that value ii is bad. By the union bound,

Pr⁡[⋃i=1kAi]≤∑i=1kPr⁡[Ai]≤∑i=1k1n2=kn2.\Pr\left[\bigcup_{i=1}^k A_i\right]\le\sum_{i=1}^k\Pr[A_i]\le\sum_{i=1}^k\frac1{n^2}=\frac{k}{n^2}.

The union bound requires no independence. For k=nk=n the bound is at most 1/n1/n.

Writing Pr⁡[⋂iAic]=∏iPr⁡[Aic]\Pr[\bigcap_i A_i^c]=\prod_i\Pr[A_i^c] requires independence. Without it, the product is unjustified.

Exercise 5 — Expectation with dependence

Let G=(V,E)G=(V,E) be a graph. For each vertex vv let IvI_v indicate that vv is selected, and assume Pr⁡[Iv=1]=p\Pr[I_v=1]=p for every vv. Let X=∑v∈VIvX=\sum_{v\in V}I_v. Prove that E[X]=∣V∣p\mathbb E[X]=|V|p even if the selection mechanism introduces dependence among vertices.

Solution

By linearity of expectation,

E[X]=E[∑vIv]=∑vE[Iv]=∑vPr⁡[Iv=1]=∣V∣p.\mathbb E[X]=\mathbb E\left[\sum_v I_v\right]=\sum_v\mathbb E[I_v]=\sum_v\Pr[I_v=1]=|V|p.

Linearity does not require independence. Dependence affects variance and tail bounds, not the expectation itself.

Summary

Complexity arguments stand on four habits: measure encoding length, expose quantifiers, match the proof method to the claim, and define the probability experiment. These habits will reappear in simulations, hierarchy arguments, nondeterministic computation, and padding.

Guided practice

Task 1 — Quantifiers and constant dependence

State precisely and compare the strength of:

  1. For every machine MM there is a constant cMc_M such that for every input xx, TM(x)≤2cM ∣x∣T_M(x)\le 2^{c_M\,|x|}.
  2. There is a single constant cc such that for every machine MM and every input xx, TM(x)≤2c ∣x∣T_M(x)\le 2^{c\,|x|}.

In which statement may the constant depend on MM? May one choose the constant after seeing xx?

Solution

The first statement is

∀M ∃cM ∀x: TM(x)≤2cM ∣x∣.\forall M\ \exists c_M\ \forall x:\ T_M(x)\le 2^{c_M\,|x|}.

The constant may depend on MM but not on xx: one may not choose cMc_M after seeing xx.

The second is

∃c ∀M ∀x: TM(x)≤2c ∣x∣,\exists c\ \forall M\ \forall x:\ T_M(x)\le 2^{c\,|x|},

and is much stronger. Writing the dependence in a subscript (cMc_M versus cc) prevents exam confusion.

Task 2 — Three parts of a membership proof

Let LL be a language. State exactly what must be proved to claim L∈CL\in\mathcal C when C\mathcal C is defined via machines with a given resource bound. Explain why a single example input is insufficient, and why an additional slow algorithm does not disprove membership.

Solution

Separate three obligations:

  1. Semantics: the machine accepts exactly the strings of LL and rejects the complement.
  2. Halting: every required computation halts (accept and reject).
  3. Resources: the bound holds for every input of length nn, including no-instances.

Examples do not discharge ∀x\forall x. Class membership is existential in the algorithm: one correct machine suffices; another slow machine does not disprove membership.

Task 3 — Capstone: time, encoding, and probability

An algorithm receives a binary integer NN, launches NN trials, and each trial has a bad event with probability at most 1/N31/N^3 (no independence among trials).

  1. Prove the algorithm is not polynomial in the input length n=∣N∣n=|N|.
  2. Bound the probability of any bad event.
  3. Explain when failure probability <1<1 proves existence of a good choice, and when that is not enough for an efficient algorithm.
  4. Distinguish expected time from worst-case time.
Solution
  1. The input length is n=Θ(log⁡N)n=\Theta(\log N). Launching NN trials takes at least N=2Θ(n)N=2^{\Theta(n)} steps, so the time is not polynomial in nn.

  2. By the union bound, without independence:

Pr⁡[some bad event]≤N⋅N−3=N−2=2−Θ(n).\Pr[\text{some bad event}]\le N\cdot N^{-3}=N^{-2}=2^{-\Theta(n)}.
  1. If Pr⁡[failure]<1\Pr[\text{failure}]<1 then Pr⁡[success]>0\Pr[\text{success}]>0, so a good randomness choice exists (the probabilistic method). Existence does not yield an efficient algorithm for finding the choice; that needs sampling, repetition, derandomization, or search.

  2. Small expected time does not imply a polynomial bound on every run. A rare huge runtime can keep expectation small while destroying worst-case polynomiality.

In every probabilistic argument, state the distribution, the random variable, whether the bound is expectation or a tail, and what is required for every input.

Sources

  • Student-summary evidence: merged course summary, pp. 1, 98, and 141. It is an image-based student summary and is used only to align emphasis and terminology, not as final authority.
  • Course evidence: Semester A 2026 transcripts 1-2 for foundational course framing; no exact line locator is asserted here.
  • Verification: Michael Sipser, Introduction to the Theory of Computation, 3e, pp. 3-24.
  • Verification: Sanjeev Arora and Boaz Barak, Computational Complexity: A Modern Approach draft, pp. 9-14 and Appendix A.
  • Verification: Christos Papadimitriou, Computational Complexity, pp. 1-18 and elementary probability material in Chapter 11.