What is the training time complexity of building a Random Forest with B trees, N samples and M features?

Last updated 5 November 2026

  • For balanced trees, training costs about O(B · m · N log² N), where m (mtry) is the features tried per split. Presorting or histograms reduce this to about O(B · m · N log N).

  • Each level costs O(m · N log N) (sorting plus scanning per feature), and a balanced tree has about log N levels. A degenerate chain-like tree worsens to O(m · N² log N).

  • Cost is linear in B, and using m ≪ M makes RF trees cheaper than full CART trees (O(M · N log² N)).

  • https://pub.towardsai.net/mastering-random-forest-a-deep-dive-with-gradient-boosting-comparison-2fc50427b508
  • https://medium.com/@ryassminh/time-complexity-in-ml-ensuring-model-performance-with-growing-data-sizes-42007e5b7305
  • http://sergiorivera.dev/blog/decision-trees/
All Random Forests interview questions