CoursifyCoursify

Short Notes on Cook's Theorem, Randomized Algorithms, and Bin Packing

Short Notes on Cook's Theorem, Randomized Algorithms, and Bin Packing

Verified Sources
May 27, 2026

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

3

Footnotes

  1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. 2 3

  2. Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. 2 3

  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

  1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions.

  2. Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification.

  3. 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:

  1. SAT belongs to NP because, given a truth assignment, one can verify in polynomial time whether the Boolean formula is satisfied.
  2. Every problem in NP can be reduced to SAT by a polynomial-time reduction.2

Formally, if LNPL \in \mathrm{NP}, then there exists a polynomial-time computable function ff such that

xL    f(x)SAT.x \in L \iff f(x) \in \mathrm{SAT}.

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

  1. 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

  2. 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

  3. 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

  1. 1
    Step 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

    1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions.

    2. Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT.

  2. 2
    Step 2

    Encode each time step and tape cell as part of a structured table describing machine configurations over time.2

    Footnotes

    1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions.

    2. Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT.

  3. 3
    Step 3

    Introduce variables that indicate which symbol or machine state appears in each position of the tableau.2

    Footnotes

    1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions.

    2. Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT.

  4. 4
    Step 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

    1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions.

    2. Introduction to Theoretical Computer Science: NP, NP completeness, and the Cook-Levin Theorem - Textbook-style explanation of encoding NP computations into SAT.

  5. 5
    Step 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

    1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions.

    2. 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 P=NPP = NP.2

Footnotes

  1. 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.

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:

TypeCorrectnessRunning timeExample behavior
Las Vegas algorithmAlways correctRandom variableRandomized quicksort with expected O(nlogn)O(n \log n) time2
Monte Carlo algorithmMay err with small probabilityUsually bounded/fixedRandomized 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 TT is a random variable for runtime, then one often studies E[T]\mathbb{E}[T] rather than only the worst case.2 For example, randomized quicksort has expected complexity

E[T(n)]=O(nlogn),\mathbb{E}[T(n)] = O(n \log n),

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 1/21/2, then after kk independent repetitions the failure probability can drop to at most

(12)k.\left(\frac{1}{2}\right)^k.

This is one reason randomized methods are often practical despite allowing a tiny probability of error.

Footnotes

  1. 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

  2. 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

  1. 1
    Step 1

    Identify which choices are random, such as pivot selection, random vectors, or sampled edges.2

    Footnotes

    1. 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.

  2. 2
    Step 2

    State whether the algorithm is always correct, or whether it has a bounded probability of error.2

    Footnotes

    1. 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.

  3. 3
    Step 3

    Use expected time, variance, or high-probability bounds instead of relying only on deterministic worst-case analysis.2

    Footnotes

    1. 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.

  4. 4
    Step 4

    For Monte Carlo methods, quantify how likely an incorrect answer is on one run.

    Footnotes

    1. Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification.

  5. 5
    Step 5

    Repeat the algorithm independently to make the probability of overall failure exponentially small.

    Footnotes

    1. 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 O(nlogn)O(n \log n).2

Footnotes

  1. 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.

Common Misconception

Randomized does not mean unstructured or unreliable. In rigorous analysis, both expected running time and error probability are mathematically bounded.2

Footnotes

  1. 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.

(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 s1,s2,,sns_1,s_2,\dots,s_n with 0<si10 < s_i \le 1, the goal is to partition them into the fewest bins such that the sum in each bin is at most 11.2

The decision version—whether all items can be packed into at most kk bins—is NP-complete, while the optimization version is NP-hard.2 Because of this, exact polynomial-time algorithms are not expected unless P=NPP = NP.

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:

FFD(I)119OPT(I)+69,\mathrm{FFD}(I) \le \frac{11}{9}\mathrm{OPT}(I) + \frac{6}{9},

where OPT(I)\mathrm{OPT}(I) is the minimum number of bins for instance II.

This illustrates a core theme of approximation algorithms: when exact optimization is hard, one seeks solutions that are provably close to optimal.2

2

Footnotes

  1. 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

  2. Approximation Algorithms for Multidimensional Bin Packing - Georgia Tech Thesis - Background on bin packing hardness, applications, and approximation context. 2 3

  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

  1. 1
    Step 1

    Arrange all item sizes in non-increasing order so large items are considered first.2

    Footnotes

    1. 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.

  2. 2
    Step 2

    Maintain the current list of bins and their remaining capacities.

    Footnotes

    1. Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD.

  3. 3
    Step 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

    1. Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD.

  4. 4
    Step 4

    If no existing bin can hold the item, open a new bin and place the item there.

    Footnotes

    1. Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD.

  5. 5
    Step 5

    The algorithm outputs a feasible packing that is not always optimal but has strong theoretical guarantees and good practical performance.2

    Footnotes

    1. 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.

Conceptual Comparison of the Three Topics

Comparison by theoretical role in computer science

Conceptual Roadmap

Cook and Levin

1971

SAT was established as NP-complete, giving the first cornerstone result in NP-completeness theory."

Footnotes

  1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions.

Growth of randomized methods

Later development

Randomized algorithms became a major paradigm for expected-time efficiency and bounded-error computation.2"

Footnotes

  1. 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 research

Approximation era

Bin packing became a classic NP-hard problem studied through heuristics, approximation ratios, and practical optimization methods.2"

Footnotes

  1. 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.

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

  1. Cook–Levin theorem - Wikipedia - Overview of the theorem stating SAT is NP-complete and explaining polynomial-time reductions. 2

  2. NP Completeness - University of Virginia Slides - Slides summarizing NP-hardness, NP-completeness, and the significance of Cook/Levin.

  3. Lecture 18: Randomized Algorithms - Harvard - Lecture notes defining Las Vegas and Monte Carlo algorithms, expected runtime, and error amplification. 2

  4. Notes on Randomized Algorithms - Yale - Notes discussing probabilistic analysis and the Las Vegas versus Monte Carlo distinction.

  5. Bin packing problem - Wikipedia - Overview of bin packing, hardness, heuristics, and approximation guarantees including FFD. 2

  6. Approximation Algorithms for Bin Packing: A Survey - Survey covering classical heuristics such as FFD and their worst-case performance.

Knowledge Check

Question 1 of 4
Q1Single choice

What is the main statement of Cook's theorem?

Chat with Kiro