Tutorials › Regression Analysis (Undergraduate) › Computational Limits of Exhaustive Search

Subset and Stepwise Selection · Tutorial 644 of 991

Computational Limits of Exhaustive Search

See why exhaustive regression searches become costly as predictors accumulate, and how branch-and-bound can reduce the search without sacrificing the exact answer.

Advanced 11 min read

What You'll Learn

  • Count the candidate regression models for a given number of predictors
  • Distinguish the search for best subsets by size from the final choice of model size
  • Explain why exhaustive search grows exponentially
  • Use nested-model residual sums of squares to form a branch-and-bound lower bound
  • Identify when pruning preserves an exact best-subset answer and when it cannot help

Why Exhaustive Search Becomes Expensive

Best-subset selection asks which combinations of candidate predictors give the strongest models. Its appeal is straightforward: unlike a search that follows only one path through the candidates, exhaustive search can compare every allowed subset. Its cost grows rapidly, however. With \(p\) candidate predictors, each predictor is either included or excluded, creating \(2^p\) possible subsets.

The exponential count matters because each candidate model may require a regression fit and a score, such as residual sum of squares (RSS) or a model-selection criterion. A search that is practical for a handful of predictors can become infeasible as \(p\) grows. Branch-and-bound addresses this computational problem: it can skip groups of candidate models when a valid bound shows that none can improve the best model found so far.

What Is Being Counted?

Definition: Given \(p\) candidate predictors, a subset model includes any chosen subset of those predictors, with the intercept handled consistently across models if one is used. The empty subset is the intercept-only model. There are \(2^p\) subsets in total, including the empty subset and the model containing all \(p\) predictors.

The count follows because each predictor has two choices, included or excluded. Multiplying the two choices across \(p\) predictors gives \(2\times2\times\cdots\times2=2^p\). If the intercept-only model is not counted as a candidate, the number is \(2^p-1\). The intercept does not count as one of the \(p\) candidate predictors.

$$ \text{Number of subsets of size } k=\binom{p}{k}, \qquad \text{total number of subsets}=\sum_{k=0}^{p}\binom{p}{k}=2^p. $$

The first formula counts subsets of a particular size \(k\): choose \(k\) predictors from \(p\). The second adds the counts at all sizes. Exhaustive best-subset procedures commonly find the best model at each size, then use a chosen criterion to compare sizes. They need not use the same criterion for both tasks.

Worked Example: Counting Models With Five Predictors

Suppose a hypothetical analysis has five candidate predictors, \(X_1,\ldots,X_5\). How many subset models are possible, and how many contain exactly two predictors?

Each predictor is either included or excluded, so the total is \[ 2^5=32. \] This includes the intercept-only model and the model with all five predictors. If only models with at least one predictor are counted, there are \(32-1=31\).

For exactly two predictors, the number is \[ \binom{5}{2}=\frac{5!}{2!3!}=\frac{120}{12}=10. \] Thus a search organized by model size compares 1 model of size 0, 5 of size 1, 10 of size 2, 10 of size 3, 5 of size 4, and 1 of size 5; these counts sum to 32.

The Computational Growth

The count doubles whenever one additional candidate predictor is added: \(2^{p+1}=2\cdot2^p\). This is exponential growth, not a small fixed increase per predictor. The following counts include the empty subset.

Number of predictors \(p\)Number of subsets \(2^p\)
101,024
201,048,576
301,073,741,824
401,099,511,627,776

For scale, if fitting and scoring each model took an idealized one millisecond, a serial search over the \(2^{30}\) subsets would take about \(1{,}073{,}742\) seconds, or 12.4 days. Real computation also has overhead, and the time per fit depends on the data and implementation. The calculation is only an illustration, but it shows why an algorithm that avoids some fits may be valuable.

Worked Example: Finding the Number of Size-Two Models

A hypothetical dataset has eight candidate predictors. Before fitting anything, determine how many models have exactly two predictors and what fraction of all subsets they represent.

The number of size-two models is \[ \binom{8}{2}=\frac{8!}{2!6!}=\frac{8\cdot7}{2}=28. \] There are \(2^8=256\) subsets overall, so the fraction that have size two is \[ \frac{28}{256}=0.1094, \] or about 10.94%. This count can help plan a search by size, but it does not remove the need to consider the other sizes if the final choice is to be made across all subset sizes.

Branch-and-Bound: Search With a Safe Bound

Branch-and-bound organizes candidate subsets into branches. At a branch point, some predictors have been selected, some excluded, and some left undecided. Instead of fitting every completion of that partial choice, the algorithm calculates a bound on how good any completion could possibly be. If even that bound cannot beat the current best candidate, the whole branch can be pruned.

For least-squares best subsets, a useful fact is that adding predictors cannot increase the minimum RSS when the response, observations, and fitting rules stay fixed. The larger model can always set the added coefficients to zero and reproduce the smaller model's fit. Therefore, the RSS of the model containing all selected and undecided predictors is a lower bound on the RSS of each of its smaller descendant models.

Key result: To find the minimum-RSS subset of a fixed size \(k\), a branch may be pruned if the RSS from fitting all predictors that are either already selected or still undecided is strictly greater than the RSS of the best size-\(k\) model already found. Every feasible size-\(k\) completion then has RSS at least as large as that bound and cannot improve the incumbent.

Why the Bound Is Valid

Let \(S\) be the predictors already selected at a branch, \(U\) the undecided predictors, and \(E\) the predictors excluded. Any completion of that branch uses a subset of \(S\cup U\). Denote by \(\operatorname{RSS}(A)\) the least-squares RSS for the model using predictor set \(A\), with the same intercept convention throughout.

The fitted values available to a model using a subset of \(S\cup U\) are also available to the model using all of \(S\cup U\): it can set coefficients for unused predictors to zero. Since least squares minimizes RSS over the available fitted values, the larger model's minimum RSS cannot be greater. Thus, for every completion \(C\) of the branch,

$$ C\subseteq S\cup U \quad\Longrightarrow\quad \operatorname{RSS}(S\cup U)\leq \operatorname{RSS}(C). $$

For a fixed target size \(k\), if the incumbent has RSS \(R_k\) and \(\operatorname{RSS}(S\cup U)>R_k\), then every feasible completion has RSS greater than \(R_k\). None can be the minimum-RSS size-\(k\) subset. The strict inequality avoids discarding a tied optimum; if only one optimum is required, a tie can be handled according to the algorithm's stated tie rule.

This argument is an exact justification for pruning, not a heuristic guess about which predictors are promising. It relies on a valid bound and on comparing models under the same least-squares setup. A bound that is merely plausible, rather than guaranteed, could remove the true best model.

Worked Example: Pruning a Branch for Size-Two Models

Consider a hypothetical search with four candidate predictors \(A,B,C,D\), seeking the minimum-RSS model of size two. The search has already fitted model \(\{A,B\}\), with RSS 20, so the current best size-two model has RSS \(R_2=20\). A branch has selected \(A\), excluded \(B\), and left \(C\) and \(D\) undecided.

The feasible size-two completions of this branch are \(\{A,C\}\) and \(\{A,D\}\). Fit the larger model containing all selected and undecided predictors, \(\{A,C,D\}\). Suppose its hypothetical least-squares RSS is 24. Because each completion is nested within that model, \[ \operatorname{RSS}(\{A,C,D\})=24 \leq \operatorname{RSS}(\{A,C\}),\quad \operatorname{RSS}(\{A,D\}). \] Both completions therefore have RSS at least 24, which is greater than the incumbent value 20. The branch can be pruned without fitting either size-two completion: neither can beat the current best.

The numerical summaries are consistent with the nesting property: adding predictors can reduce RSS, so the larger model's value of 24 is no greater than the RSS of either smaller completion. This does not mean the branch's models are known to have RSS exactly 24; the bound is enough to rule them out.

From Best RSS at Each Size to a Selection Criterion

Many best-subset procedures first identify the lowest-RSS model at each size. They then compare those size-specific winners using a criterion such as AIC, BIC, or Mallows \(C_p\). For a fixed size and the usual least-squares versions of these criteria, the penalty for model size is constant, so lower RSS gives the preferred model at that size. Once the best model for each size is known, the selected size can be determined by the specified criterion.

Branch-and-bound can therefore preserve the exhaustive answer by finding the exact minimum-RSS subset at every required size, then applying the same criterion to those winners. It changes which models must be fitted, not the definition of the winner. This guarantee depends on using a valid pruning bound and searching all branches that could still contain an improvement.

The least-squares nesting argument is algebraic; it does not require normally distributed errors. If the goal is statistical inference rather than computational comparison, the relevant regression assumptions still matter for that inference. And if candidate models are subject to extra restrictions, such as grouped inclusion rules, the branches and bounds must respect those restrictions.

What Branch-and-Bound Can and Cannot Promise

Branch-and-bound can substantially reduce the number of fitted models when the bounds quickly become worse than an incumbent. Its savings are data- and problem-dependent, however. If bounds are weak, or many models remain potentially competitive, the search may approach the exhaustive count. In the worst case, branch-and-bound still has exponential computational cost.

The method also has costs of its own: it must organize the search, calculate bounds, and maintain the best candidates found so far. Whether it is faster depends on whether the avoided fits outweigh that overhead. Most importantly, fewer fitted models do not by themselves mean a less accurate answer. With valid bounds, the exact best-subset result is unchanged; without valid bounds, pruning can turn an exact search into an unreliable shortcut.

Common Mistake

  • Wrong reasoning: “Branch-and-bound is faster because it skips models, so it must return an approximate answer.”
  • Correction: It can return the exact best-subset answer if every pruned branch is ruled out by a mathematically valid bound. The number of fits may be lower, but the best model is unchanged.
  • Another pitfall: “The search fits fewer models, so its runtime is guaranteed to be small.” Avoided fits do not guarantee a large saving; bounds can be weak, and worst-case growth remains exponential.
Key takeaway: Exhaustive search considers \(2^p\) subsets because every predictor can be included or excluded. Branch-and-bound can cut that computation by eliminating branches whose best possible completion cannot improve the current winner. The result is exact only when the bounds and pruning rules are valid.

Check Your Understanding

Try these questions without looking back.

  1. How many subsets, including the empty subset, are there for seven candidate predictors? How many have exactly three predictors?
  2. Why does adding a predictor to a least-squares model never increase its minimum RSS when the data and fitting rules are unchanged?
  3. A branch's lower bound for size-four models is RSS 31, while the incumbent size-four model has RSS 28. What can the search conclude about that branch?
  4. Why is finding the best model at each size distinct from choosing the final model size?
  5. Does branch-and-bound guarantee a large reduction in computation? Explain what it does guarantee when its pruning bounds are valid.