Short Notes on Cook's Theorem, Randomized Algorithms, and Bin Packing
These three topics occupy central positions in computational complexity, algorithm design, and approximation theory. Cook's theorem explains why SAT is historically foundational in NP-completeness; randomized algorithms show how randomization can improve performance or simplicity; and bin packing illustrates a classic NP-hard optimization problem where exact solutions are difficult but practical heuristics and approximation methods are powerful.3
A useful way to relate them is this: Cook's theorem establishes a framework for proving intractability via reductions, randomized algorithms provide alternative design strategies when deterministic methods are expensive or awkward, and bin packing is a canonical example of a hard problem that motivates approximation and heuristic approaches.3
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩ ↩2 ↩3
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩ ↩2 ↩3
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩ ↩2 ↩3
Introductory Video on NP-Hard and NP-Complete Problems
How to Read These Notes
Cook's theorem is primarily a complexity-theory result, randomized algorithms are a design paradigm, and bin packing is an optimization problem. Together they show three major perspectives in theoretical computer science: hardness, probabilistic computation, and approximation.3
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩
(a) Cook's Theorem
Cook's theorem—more precisely the Cook–Levin theorem—states that the Boolean satisfiability problem is NP-complete. This means two things hold:
- SAT belongs to NP because, given a truth assignment, one can verify in polynomial time whether the Boolean formula is satisfied.
- Every problem in NP can be reduced to SAT by a polynomial-time reduction.2
Formally, if , then there exists a polynomial-time computable function such that
This is the key statement that makes SAT the first known NP-complete problem.2
The theorem is historically important because it launched the modern theory of NP-completeness and enabled thousands of later hardness proofs through chains of reductions.2 Once SAT was shown NP-complete, researchers could prove another problem hard by reducing SAT or another NP-complete problem to it.
The proof idea is to encode the computation of a nondeterministic Turing machine on an input as a Boolean formula.2 The formula describes a computation tableau ensuring:
- the initial configuration is correct,
- each step follows the machine's transition rules,
- and some accepting configuration is reached.2
Thus, the formula is satisfiable exactly when the original machine has an accepting computation path.2
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8
-
Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT. ↩ ↩2 ↩3 ↩4 ↩5 ↩6
-
NP Completeness - University of Virginia Slides - Slides summarizing NP-hardness, NP-completeness, and the significance of Cook/Levin. ↩
Core Idea of the Cook–Levin Proof
- 1Step 1
Assume a language is decided by a nondeterministic Turing machine in polynomial time. This gives a polynomial bound on the length of any accepting computation.2
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩
-
Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT. ↩
-
- 2Step 2
Encode each time step and tape cell as part of a structured table describing machine configurations over time.2
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩
-
Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT. ↩
-
- 3Step 3
Introduce variables that indicate which symbol or machine state appears in each position of the tableau.2
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩
-
Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT. ↩
-
- 4Step 4
Construct clauses forcing valid initial conditions, legal transitions, and eventual acceptance. These clauses remain polynomial in number because the machine runs for polynomially many steps.2
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩
-
Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT. ↩
-
- 5Step 5
The resulting Boolean formula is satisfiable exactly when the machine accepts the input, proving every NP problem reduces to SAT in polynomial time.2
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩
-
Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT. ↩
-
Exam Point
If SAT were solved in polynomial time, then every problem in NP would also be solvable in polynomial time, implying .2
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩
-
NP Completeness - University of Virginia Slides - Slides summarizing NP-hardness, NP-completeness, and the significance of Cook/Levin. ↩
Cook's Theorem: Key Clarifications
(b) Randomized Algorithms
A randomized algorithm is an algorithm that makes decisions using random bits during execution.2 Unlike deterministic algorithms, its behavior may vary across different runs on the same input. The analysis therefore studies both running time and probability of correctness.2
Two major classes are commonly distinguished:
| Type | Correctness | Running time | Example behavior |
|---|---|---|---|
| Las Vegas algorithm | Always correct | Random variable | Randomized quicksort with expected time2 |
| Monte Carlo algorithm | May err with small probability | Usually bounded/fixed | Randomized verification procedures such as Freivalds' test |
Randomized algorithms are valuable because they can be simpler, faster in expectation, or easier to analyze than deterministic alternatives.2 They are especially useful in primality testing, hashing, matrix verification, minimum cut, load balancing, and geometric computation.2
A central concept is expected running time. If is a random variable for runtime, then one often studies rather than only the worst case.2 For example, randomized quicksort has expected complexity
even though some unlucky pivot choices can still lead to quadratic behavior.2
For Monte Carlo algorithms, repeated independent trials can reduce the error probability, a technique called amplification. If a single trial fails with probability at most , then after independent repetitions the failure probability can drop to at most
This is one reason randomized methods are often practical despite allowing a tiny probability of error.
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10
-
Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7
How Randomized Algorithms Are Typically Analyzed
- 1Step 1
Identify which choices are random, such as pivot selection, random vectors, or sampled edges.2
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction. ↩
-
- 2Step 2
State whether the algorithm is always correct, or whether it has a bounded probability of error.2
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction. ↩
-
- 3Step 3
Use expected time, variance, or high-probability bounds instead of relying only on deterministic worst-case analysis.2
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction. ↩
-
- 4Step 4
For Monte Carlo methods, quantify how likely an incorrect answer is on one run.
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
- 5Step 5
Repeat the algorithm independently to make the probability of overall failure exponentially small.
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
Always returns a correct answer, but the runtime depends on random choices. A classic example is randomized quicksort, whose expected running time is .2
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction. ↩
Common Misconception
Randomized does not mean unstructured or unreliable. In rigorous analysis, both expected running time and error probability are mathematically bounded.2
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction. ↩
(c) Bin Packing
The bin packing problem asks for the minimum number of bins of equal capacity needed to pack items of given sizes so that the total size in any bin does not exceed the capacity. In the standard one-dimensional version, if items have sizes with , the goal is to partition them into the fewest bins such that the sum in each bin is at most .2
The decision version—whether all items can be packed into at most bins—is NP-complete, while the optimization version is NP-hard.2 Because of this, exact polynomial-time algorithms are not expected unless .
Bin packing has practical applications in memory allocation, cutting stock, cargo loading, scheduling, and resource consolidation.2 Its importance comes from the fact that it is easy to state, computationally hard, and rich in heuristic and approximation techniques.2
Several classical heuristics are used:
- Next Fit
- First Fit
- Best Fit
- First Fit Decreasing2
Among these, First Fit Decreasing (FFD) is especially important. It first sorts items in non-increasing order and then applies First Fit.2 It is fast and often near-optimal in practice. A classical bound states:
where is the minimum number of bins for instance .
This illustrates a core theme of approximation algorithms: when exact optimization is hard, one seeks solutions that are provably close to optimal.2
Footnotes
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11
-
Approximation Algorithms for Multidimensional Bin Packing - Georgia Tech Thesis - Background on bin packing hardness, applications, and approximation context. ↩ ↩2 ↩3
-
Approximation Algorithms for Bin Packing: A Survey - Survey covering classical heuristics such as FFD and their worst-case performance. ↩ ↩2 ↩3 ↩4 ↩5
First Fit Decreasing for Bin Packing
- 1Step 1
Arrange all item sizes in non-increasing order so large items are considered first.2
Footnotes
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩
-
Approximation Algorithms for Bin Packing: A Survey - Survey covering classical heuristics such as FFD and their worst-case performance. ↩
-
- 2Step 2
Maintain the current list of bins and their remaining capacities.
Footnotes
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩
-
- 3Step 3
For each item in sorted order, scan bins from left to right and place it into the first bin that has enough free space.
Footnotes
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩
-
- 4Step 4
If no existing bin can hold the item, open a new bin and place the item there.
Footnotes
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩
-
- 5Step 5
The algorithm outputs a feasible packing that is not always optimal but has strong theoretical guarantees and good practical performance.2
Footnotes
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩
-
Approximation Algorithms for Bin Packing: A Survey - Survey covering classical heuristics such as FFD and their worst-case performance. ↩
-
Conceptual Comparison of the Three Topics
Comparison by theoretical role in computer science
Conceptual Roadmap
Cook and Levin
1971SAT was established as NP-complete, giving the first cornerstone result in NP-completeness theory."
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩
Growth of randomized methods
Later developmentRandomized algorithms became a major paradigm for expected-time efficiency and bounded-error computation.2"
Footnotes
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩
-
Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction. ↩
Bin packing research
Approximation eraBin packing became a classic NP-hard problem studied through heuristics, approximation ratios, and practical optimization methods.2"
Footnotes
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩
-
Approximation Algorithms for Bin Packing: A Survey - Survey covering classical heuristics such as FFD and their worst-case performance. ↩
Comparative Review
Concluding Note
In short, Cook's theorem is the foundational result proving that SAT is NP-complete and establishing the reduction-based framework of complexity theory.2 Randomized algorithms are algorithms that exploit random choices to obtain simplicity, speed, or bounded-error guarantees, usually analyzed through expectation and probability.2 Bin packing is a classical NP-hard optimization problem concerned with minimizing the number of fixed-capacity bins, and it is commonly addressed using heuristics such as First Fit and First Fit Decreasing, along with approximation analysis.2
Together, these topics represent three enduring ideas in computer science: proving hardness, designing with randomness, and coping with intractability through approximation.3
Footnotes
-
Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. ↩ ↩2
-
NP Completeness - University of Virginia Slides - Slides summarizing NP-hardness, NP-completeness, and the significance of Cook/Levin. ↩
-
Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. ↩ ↩2
-
Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction. ↩
-
Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. ↩ ↩2
-
Approximation Algorithms for Bin Packing: A Survey - Survey covering classical heuristics such as FFD and their worst-case performance. ↩
Knowledge Check
What is the main statement of Cook's theorem?
Explore Related Topics
Introduction to Randomized Algorithms
Inverted Page Table
The Banker's Algorithm: Deadlock Avoidance in Operating Systems
The Banker's Algorithm is a deadlock‑avoidance method that keeps a system in a safe state by checking each resource request against the maximum declared needs of processes.
- Maintains Available, Max, Allocation, and Need matrices, where .
- The Safety Algorithm uses vectors Work and Finish to find an execution order; if all processes finish, the state is safe.
- The Resource‑Request Algorithm simulates allocation, runs the safety check, and commits only if the resulting state remains safe.
- Time complexity of the safety check is .
- In practice the algorithm is rarely used because processes must predeclare maximum needs and the algorithm’s overhead is high.
