Optimal Decision Tree Pruning Revisited: Algorithms and Complexity

Juha Harviainen, Frank Sommer, Manuel Sorge, Stefan Szeider

Abstract

Pruning is a critical step in decision tree induction used to prevent overfitting and improve model interpretability. This study provides a comprehensive analysis of the computational complexity associated with two standard pruning operations: subtree replacement and subtree raising. We establish that while subtree replacement can be performed optimally in polynomial time, subtree raising is NP-complete. To address this, we propose several fixed-parameter tractable (FPT) algorithms. Our experimental results on 40 benchmark datasets reveal that existing heuristics, such as those in C4.5, frequently produce results close to the theoretical optimum.

Introduction

Decision trees are widely utilized in machine learning due to their inherent interpretability. However, they are susceptible to overfitting, necessitating pruning to balance model size against classification accuracy. Pruning typically involves two primary operations:

  1. Subtree Replacement: A node and its entire descendants are replaced by a single leaf node.
  2. Subtree Raising: A node is replaced by one of its subtrees, effectively moving a deeper branch higher up the tree.
Illustration of pruning operations: (a) original tree, (b) subtree replacement, and (c) subtree raising.

Despite their widespread use in algorithms like C4.5 and CART, the theoretical complexity of finding an optimal pruned tree—one that minimizes errors for a given size constraint—has remained largely unexplored until now.

Computational Complexity and Algorithms

The core contribution of this work is the identification of a "complexity gap" between the two pruning methods.

Subtree Replacement

We show that optimal subtree replacement is computationally efficient. We present a dynamic programming (DP) algorithm that finds the optimal tree in $O((n + \min\{k^2, t^2\}) \cdot s)$ time, where $s$ is the tree size, $k$ is the number of nodes removed, and $t$ is the number of errors. This improves upon previous quadratic-time approaches by utilizing heavy-light decomposition to speed up example classification.

Subtree Raising

In contrast, we prove that optimal subtree raising is NP-complete, even for trees with a small number of features. The proof utilizes a reduction from the $\kappa$-BICLIQUE problem. However, the problem becomes tractable under certain parameterizations. We provide an FPT algorithm that runs in $O(D^{2d} \cdot |I|^{O(1)})$ time, where $D$ is the domain size and $d$ is the feature count.

Complexity landscape for decision tree pruning under various parameters, highlighting FPT, XP, and paraNP-hard regions.

Empirical Results

We evaluated our optimal algorithms against 40 datasets from the Penn Machine Learning Benchmarks (PMLB). A key finding is that standard heuristics are remarkably effective. In 36 of the 40 datasets, the heuristic used by WEKA's J48 (a C4.5 implementation) reached the theoretical Pareto front—meaning no algorithm could have pruned the same number of nodes with fewer errors. In cases where the heuristic was sub-optimal, the improvement offered by the optimal DP algorithm was marginal, such as reducing errors from 8 to 7 in the soybean dataset for the same tree size.

Conclusion

This research clarifies the algorithmic boundaries of decision tree pruning. While subtree raising adds significant complexity, the practical performance of existing heuristics suggests they are well-suited for most real-world applications. Future work will extend these analyses to tree ensembles, where we have already shown that optimal pruning is NP-hard even for an ensemble of just two trees.

Summary updated

BibTeX
@inproceedings{harviainen2025optimal,
  author = {Juha Harviainen and Frank Sommer and Manuel Sorge and Stefan Szeider},
  title = {{Optimal Decision Tree Pruning Revisited: Algorithms and Complexity}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=iUsHLRTp3t},
}
Figure