Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How to Learn Schöning’s Random-Walk k-SAT Algorithm: Unsatisfied Clauses, Hamming Distance, Random Restarts and O*((2−2/k)^n) Search

Three students studying together in an eduKate small-group classroom.

Can an NP-complete satisfiability problem be attacked by an algorithm almost simple enough to explain in a minute? Schöning’s randomized k-SAT algorithm starts from a random truth assignment, repeatedly chooses an unsatisfied clause, flips a random variable inside it, and restarts. That tiny rule produces the classic O*((2−2/k)n) exact-algorithm bound—O*((4/3)n) for 3-SAT.

This Learning Hall article develops the algorithm from Boolean formulas and Hamming distance, explains why an unsatisfied clause always contains a potentially helpful flip, derives the random-walk intuition, distinguishes theory from modern CDCL practice, and finishes with restart engineering, testing and pedagogy.

Quick Read

  • k-SAT asks whether a CNF formula with clauses of at most k literals has a satisfying assignment.
  • Start from a uniformly random assignment.
  • If the formula is satisfied, stop.
  • Otherwise choose any unsatisfied clause.
  • Choose one variable from that clause uniformly at random and flip it.
  • Repeat for O(n) steps, then restart from a new random assignment.
  • Relative to any fixed satisfying assignment, an unsatisfied k-clause contains at least one variable whose flip moves one Hamming step closer.
  • This gives a biased random-walk analysis.
  • The classical expected/exponential running-time bound is O*((2−2/k)n).
  • For 3-SAT this becomes O*((4/3)n), much better than 2n brute force in the exponent.

1. Beginner Level: What Is k-SAT?

A literal is a Boolean variable x or its negation ¬x. A clause is an OR of literals, and a CNF formula is an AND of clauses.

(x1 OR not x4 OR x7)
AND
(not x2 OR x3 OR x9)
AND
...

In k-SAT, every clause contains at most k literals. The task is to find an assignment of true/false values that satisfies every clause, or determine that none exists.

2. The Algorithm Is Local Search

Maintain one complete truth assignment. If some clause is false, then every literal in that clause is currently false. Pick one of its variables and flip the variable’s truth value.

SCHONING_TRIAL(F):
    assignment = uniformly random n-bit assignment

    repeat L times:
        if assignment satisfies F:
            return assignment

        C = any unsatisfied clause
        x = uniformly random variable occurring in C
        flip x

    return failure

Repeat independent trials until success or until the desired failure-probability budget is reached.

3. Why an Unsatisfied Clause Contains a Helpful Variable

Assume the formula is satisfiable and fix one satisfying assignment s*. If clause C is false under our current assignment a, but true under s*, then at least one literal in C must have a different truth value between a and s*.

Flipping the corresponding variable moves a one step closer to s* in Hamming distance. We do not know which variable is helpful, but in a clause of at most k variables, choosing uniformly gives probability at least 1/k of taking such a step.

4. Hamming Distance Is the Analysis Coordinate

The Hamming distance d(a,s*) is the number of variables on which assignments a and s* disagree.

At an unsatisfied clause, a random flip can reduce d by 1 with probability at least 1/k. Other choices may increase d by 1. So the algorithm behaves like a one-dimensional random walk around an unknown target assignment, even though it operates only on local unsatisfied clauses.

5. Random Initialization Matters

A uniformly random starting assignment lies at Hamming distance r from s* with probability:

Pr[d(a,s*) = r] = C(n,r) / 2^n

Most starts are around n/2 away, but exponentially many possible starts are balanced by a nontrivial probability that the subsequent walk reaches s*. The full analysis combines the distribution of starting distances with the probability of walking toward a solution before the step budget ends.

6. Why Restarts Are Essential

A single walk can drift away from every satisfying assignment. Random restarts convert a small per-trial success probability into a reliable algorithm. If each independent trial succeeds with probability p, then after R trials:

Pr[all fail] = (1-p)^R ≤ exp(-pR)

Choosing R proportional to 1/p gives constant success probability; multiplying by a logarithmic factor reduces the failure probability further.

7. The Famous Running-Time Bound

Schöning’s analysis yields a randomized exact algorithm for k-SAT with running time:

O*((2 - 2/k)^n)

For k=3:

2 - 2/3 = 4/3
so time = O*((4/3)^n)

The O* notation suppresses polynomial factors. This is an exponential-time algorithm, but its base is dramatically smaller than brute-force base 2.

8. A Small 3-SAT Trace

Suppose the current assignment makes clause:

(x2 OR not x5 OR x8)

false. Therefore x2=false, x5=true and x8=false. Pick one of {x2,x5,x8} uniformly. The chosen flip makes that literal true immediately, although it may affect other clauses. The algorithm does not greedily score the global formula; it follows the random-walk rule required by the analysis.

9. “Any Unsatisfied Clause” Is a Subtle Phrase

The proof only needs the chosen clause to be unsatisfied. Implementations may pick the first unsatisfied clause, maintain a dynamic set of unsatisfied clauses, or sample among them. But changing the variable-selection distribution or introducing heuristic bias changes the clean 1/k analysis and should be analysed separately.

10. Efficient Incremental Clause Maintenance

Re-evaluating every clause after every flip can dominate runtime. A professional implementation stores occurrence lists: for each variable, which clauses contain x and which contain ¬x. After flipping x, only those incident clauses need their satisfied-literal counts updated.

Maintain a container of currently unsatisfied clauses so selecting one does not require rescanning the formula.

11. Step Budget

For 3-SAT the algorithm is commonly presented with a linear walk length such as 3n steps per restart. General k-SAT analyses use an O(n) walk length chosen to support the success-probability proof. The exact constant is part of the theorem/implementation variant; do not treat “keep walking forever” as equivalent.

12. Schöning vs WalkSAT

Both use local flips around unsatisfied clauses, but their goals differ. Schöning’s algorithm is valued for a clean worst-case randomized exact-algorithm analysis. WalkSAT-style solvers use heuristics designed for practical performance on SAT instances and do not inherit Schöning’s proof merely because the code looks similar.

13. Schöning vs Modern CDCL

Industrial SAT solvers are dominated by conflict-driven clause learning, watched literals, restarts, branching heuristics and clause databases. Schöning is not a replacement for modern CDCL on practical benchmark suites.

Its importance is conceptual: it shows that a remarkably weak local signal—“this clause is currently false”—is enough to beat brute force in the worst-case exponential base when combined with random starts and probabilistic analysis.

14. Modern Research Context

Schöning’s random-walk framework continues to influence SAT and CSP research. Recent work still modifies its initialization or walk structure, including 2025 research on biased initialization and ICALP 2025 work that adapts Schöning-style walks to diverse-k-SAT.

15. Failure Modes

  • Choosing a satisfied clause. The “at least one helpful variable” argument is for unsatisfied clauses.
  • Flipping a random variable from the whole formula. The proof needs a variable from the chosen clause.
  • Using a deterministic initial assignment while quoting the randomized bound.
  • Stopping after one failed walk and declaring UNSAT. A failed trial proves nothing.
  • Reporting SAT without verifying the assignment. Always check all clauses before returning success.
  • Confusing high-probability failure after a budget with a proof of unsatisfiability. Schöning is Monte Carlo for finding a solution unless embedded in a complete framework with the required repetitions/logic.
  • Changing the flip distribution without updating the analysis.

16. Professional Testing Strategy

  • Generate satisfiable formulas from known planted assignments and verify returned assignments.
  • Compare tiny instances against brute-force SAT enumeration.
  • Measure success probability per restart as n and clause density vary.
  • Track Hamming distance to a planted solution during experiments to visualize the random walk.
  • Verify only clauses containing the flipped variable are updated incrementally.
  • Run with fixed random seeds for reproducibility and many independent seeds for statistical validation.
  • Test unsatisfiable instances only for bounded-run behaviour; do not interpret timeout as a proof.

17. How to Learn It Efficiently

Start with a planted 3-SAT formula on six variables and reveal the satisfying assignment only to the teacher. Give students a random starting assignment, identify an unsatisfied clause, roll a three-sided die to choose the flip, and record Hamming distance after each step.

Then use the progression trace → explain helpful flip → model Hamming walk → add restarts → derive exponential base → implement incremental clauses. Worked examples, explicit tracing and PRIMM-style prediction are well matched to randomized algorithms because learners must separate what one run does from what the probability analysis guarantees across many runs.

18. Practice Problems

  • Trace 10 random-walk steps on a supplied 3-SAT formula.
  • Prove an unsatisfied clause contains at least one variable that differs from a fixed satisfying assignment.
  • Explain why the helpful-flip probability is at least 1/k.
  • Simulate success probability from starting Hamming distance r.
  • Implement restarts and plot empirical success versus number of trials.
  • Add incremental unsatisfied-clause maintenance.
  • Compare Schöning’s algorithm with brute force and a modern SAT library on small instances.
  • Explain why a failed run is not an UNSAT certificate.

19. Sources and Further Reading

Final idea: Schöning’s algorithm is powerful because its local move has a global probabilistic interpretation. An unsatisfied clause does not tell us the solution, but it guarantees that one of a few available flips points toward any fixed satisfying assignment. Random restarts turn that weak directional signal into an exponential-time algorithm with a much smaller base than brute force.