Practice Discrete Math

Algorithms / Recursion Tree Pruning

Least You Need to Know: Recursion Trees, Feasibility Checks, and Pruning

A recursion tree shows the search branches a backtracking algorithm may explore. **Pruning** means cutting off branches as soon as a partial state can no longer lead to a valid or useful solution.

The least you need to know

Key notation

branch one recursive choice from the current partial state
prune stop exploring a branch that cannot help
feasibility check test whether the current partial state can still lead to a solution

Tiny worked example

  • Imagine placing queens row by row.
  • If a partial placement already has two queens attacking each other, no extension of that placement can become valid.
  • So you stop there instead of exploring the rest of that subtree.
  • That saved work is the whole point of pruning.

Common mistakes

How to recognize this kind of problem

Next recommended lesson

Continue through this topic with Least You Need to Know: Rolling Hashes and Substring Fingerprints.

Least You Need to Know: Rolling Hashes and Substring Fingerprints

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

Start practice