Discrete Mathsfor Engineers

Structures, proofs, and intuition

EN | PT

Backtracking

Part 5 — Pruning

Series: Backtracking Part 5 of 6

5. Pruning


Roadmap (what you will learn in this part):
  1. Why pruning is essential
  2. How constraints reduce the search space
  3. Early vs late pruning
  4. Bounding and optimization
  5. Impact on time complexity

Backtracking without pruning is often impractical.

The search tree grows exponentially, and exploring all branches quickly becomes infeasible.

Pruning is what makes backtracking efficient.

5.1 Why Pruning Matters

In many problems, the full search tree is enormous.

However, most branches do not lead to valid solutions.

Goal: avoid exploring useless branches.

Pruning allows the algorithm to skip entire subtrees that cannot produce a valid solution.

5.2 Constraint-Based Pruning

The most basic form of pruning comes from constraints.

If a partial solution violates constraints, we stop exploring immediately.

if ¬C(x₁, …, xᵢ) → prune

This is called early pruning.

5.3 Early vs Late Pruning

Pruning can happen at different stages:

  • Early pruning: reject as soon as possible
  • Late pruning: reject after deeper exploration
The earlier we prune, the more work we save.

5.4 Bounding (Optimization Problems)

In optimization problems, we can prune using bounds.

If a partial solution cannot beat the best known solution, it can be discarded.

if bound(state) ≤ best → prune

This idea is the foundation of Branch and Bound.

5.5 Impact on Complexity

In theory, backtracking is exponential.

But with effective pruning, the actual number of explored nodes can be dramatically smaller.

  • Worst case: exponential
  • With pruning: often much faster in practice

5.6 Intuition

Without pruning:

explore everything → slow

With pruning:

explore only promising paths → fast

5.7 Summary

  • Pruning eliminates useless branches
  • Constraints enable early pruning
  • Bounds enable optimization pruning
  • Efficiency depends heavily on pruning quality
Key takeaway: backtracking is only powerful when combined with pruning.

Next: Part 6 — Classic Problems

Now that we understand how backtracking works and how to make it efficient, we can study real problems.

In Part 6, we apply backtracking to classical problems such as N-Queens, permutations, and graph problems.