Recursion Pruning for the Apriori Algorithm

Christian BorgeltFIMI 2004

Abstract

This paper introduces "recursion pruning," a simple yet effective optimization for the Apriori algorithm. By adding a single-bit marker to nodes in a prefix tree, the algorithm can skip branches that do not contribute to the current counting pass. Experimental results demonstrate speedups of up to 40% on sparse datasets with zero additional memory overhead.

Introduction

The Apriori algorithm is a cornerstone of data mining, used to identify frequent itemsets within large transaction databases. However, its computational cost is significant, particularly when implemented using a prefix tree for itemset counting. During the counting phase, the algorithm performs a "doubly recursive" traversal for every transaction to find all matching subsets. As the tree grows, significant time is wasted traversing branches that do not reach the "currently deepest level" where new counts are accumulated. This paper proposes a method to eliminate these redundant traversals.

Methodology: Recursion Pruning

The proposed technique, Recursion Pruning, restricts the recursive counting process to "active" parts of the tree. Each node in the prefix tree is assigned a 1-bit marker indicating whether it has at least one descendant on the level currently being evaluated.

To maintain efficiency, this bit is incorporated into existing data fields, ensuring zero impact on the program's memory footprint. During the counting phase, if the recursion reaches an unmarked node, the algorithm immediately terminates exploration of that branch. Markers are updated every time a new level is added to the tree via a recursive traversal; a node is marked if it has marked children. This process is efficient as it leverages markers set in previous passes.

Experimental Evaluation

The algorithm was evaluated using five classic datasets: BMS-Webview-1 (web clickstream), T10I4D100K (synthetic), Census (demographic), Chess (endgames), and Mushroom (biological).

Performance on Sparse vs. Dense Data

The effectiveness of recursion pruning is highly dependent on the "shape" of the data. On sparse datasets like BMS-Webview-1, the optimization provides a significant roadmap to avoid dead ends, resulting in execution time reductions of 20% to 40%.

Execution time comparison on a sparse dataset (BMS-Webview-1), showing a significant reduction in runtime (black line) compared to the baseline (grey line).

Conversely, for dense datasets such as Census, Chess, and Mushroom, the gains were negligible. In these cases, the prefix tree is relatively "full," meaning most branches reach the deepest level and cannot be pruned. However, the overhead of checking the 1-bit marker is so small that it does not slow down the algorithm even when no pruning occurs.

Execution time on a dense dataset where recursion pruning yields negligible benefits due to the high density of the prefix tree.

Environmental Sensitivity

An interesting observation during benchmarking was the sensitivity of performance to the underlying software environment. The author noted that newer versions of the S.u.S.E. Linux distribution and the gcc compiler led to longer execution times for identical code, highlighting the importance of consistent environments in performance testing.

Conclusion

Recursion pruning is a robust, low-risk optimization for the Apriori algorithm. It offers substantial performance improvements for sparse datasets—where the computational bottleneck is most pronounced—without increasing memory usage or penalizing performance on dense data.

Summary updated

BibTeX
@inproceedings{borgelt2004recursion,
  author = {Christian Borgelt},
  title = {{Recursion Pruning for the Apriori Algorithm}},
  booktitle = {FIMI},
  year = {2004},
}
Figure