Complexity
Chapter overview: Computability asks whether a problem can be solved at all. Complexity asks how much time or other resources are required. This chapter introduces time measurement, hierarchy ideas, and deterministic versus nondeterministic computation.
8.1 Complexity
Introduction / Definition
Computational complexity studies the resources required by algorithms or machines as a function of input size. Common resources include time, space, communication, and randomness. Complexity classes group problems according to resource bounds.
Syntax / Structure / Formula
T(n) = number of computational steps on inputs of size n
Space(n) = maximum memory used
Detailed Explanation
An algorithm taking 3n+5 steps has time complexity O(n). An algorithm taking n²+2n steps has O(n²). Big-O describes an asymptotic upper bound up to constant factors.
Example
T(n)=3n+5
Therefore T(n)=O(n)
Output / Result
The algorithm grows linearly with input size.
Important Points / Notes
- Complexity is about resources, not computability.
- Asymptotic notation ignores constant factors for growth-rate analysis.
- Worst-case, average-case, and best-case analyses are different.
Mini Practice Question
Classify 7n²+3n+10 using Big-O notation.
8.2 Measuring Time Usage
Introduction / Definition
Time usage can be measured by counting elementary steps under a chosen computational model. The model must be stated because different models assign different costs. For input length n, the goal is usually to determine a function T(n) and simplify it asymptotically.
Syntax / Structure / Formula
- T(n) = c₁n + c₂n + c₃ = O(n)
Detailed Explanation
Consider a loop that executes n times and performs a constant amount of work per iteration. If each iteration costs c steps and setup costs d, T(n)=cn+d, which is O(n).
Example
for i = 1 to n:
do constant work
Output / Result
T(n)=cn+d = O(n).
Important Points / Notes
- State the cost model.
- Count dominant operations.
- Ignore lower-order terms for Big-O.
- Input size should be defined clearly.
Mini Practice Question
If an algorithm performs 5n+20 steps, what is its asymptotic time complexity?
8.3 Time Hierarchies
Introduction / Definition
Time hierarchy results show that giving a machine more time can strictly increase the set of problems it can decide. In broad terms, there are problems solvable within a larger time bound that cannot all be solved within a substantially smaller bound. This establishes a hierarchy of computational difficulty.
Syntax / Structure / Formula
- Informally: TIME(f(n)) ⊊ TIME(g(n)) under suitable growth conditions
Detailed Explanation
The hierarchy theorem prevents all efficiently bounded time classes from collapsing into one. Exact theorem statements depend on model and technical conditions, but the central idea is that more computational time can yield strictly more decision power.
Example
Compare polynomial bounds n² and n³: a hierarchy theorem studies when larger resource bounds enable strictly more languages to be decided.
Output / Result
Under appropriate formal conditions, larger time bounds define strictly stronger classes.
Important Points / Notes
- Exact hierarchy theorems have technical conditions.
- More time does not necessarily help every individual problem.
- Hierarchy results are about classes of problems.
Mini Practice Question
What does a time hierarchy result tell us about increasing computational resources?
8.4 Deterministic Computation
Introduction / Definition
In deterministic computation, the next configuration is uniquely determined by the current configuration and input. A deterministic algorithm therefore has one computation path for a given input. Deterministic Turing machines and ordinary sequential programs are standard examples.
Syntax / Structure / Formula
- δ(config) = exactly one next config
Detailed Explanation
For a deterministic algorithm, the same input and initial state produce the same execution sequence, assuming deterministic operations and environment.
Example
Input 1010
Path: C0 → C1 → C2 → ... → Chalt
Output / Result
There is one computation path for the input.
Important Points / Notes
- Determinism means no computational choice at each step.
- DFA is deterministic; NFA is nondeterministic.
- Deterministic does not mean fast.
Mini Practice Question
Can a deterministic algorithm still take exponential time? Give an example class.
8.5 Nondeterministic Computation
Introduction / Definition
Nondeterministic computation allows multiple possible next moves or can be interpreted as guessing a candidate solution and verifying it efficiently. A nondeterministic machine accepts if at least one computation path accepts. Complexity theory uses nondeterminism to define important classes such as NP.
Syntax / Structure / Formula
δ(q,a) ⊆ Q
Accept if at least one computation branch accepts.
Detailed Explanation
For a Boolean formula, a nondeterministic procedure can guess an assignment and verify whether it satisfies the formula. If some assignment works, the machine has an accepting branch.
Example
Formula: (x ∨ y) ∧ (¬x ∨ y)
Guess x,y → verify formula
Output / Result
If a satisfying assignment exists, at least one branch accepts.
Important Points / Notes
- Nondeterminism is a mathematical model.
- NP is based on polynomial-time verification/nondeterministic polynomial time.
- Nondeterministic computation is not simply random computation.
Mini Practice Question
Why does one accepting branch suffice for nondeterministic acceptance?