Research Article

A Performance Comparison of Binary Tree, Recursive Backtracking and Aldous-Broder Maze Generation Algorithms with BFS Solving in OCaml

Yuxuan Gao*
Jinling High School Hexi Campus International Department

* Corresponding author: [email protected]

Abstract

This study aimed to compare the performance of three classical maze generation algorithms including Binary Tree, Recursive Backtracking, and Aldous-Broder in terms of both generation time and subsequent solving time using Breadth-First Search (BFS). Understanding the trade-offs between generation speed and solving efficiency is important for beginners in algorithm design and for applications such as game development and procedural content generation. All three generation algorithms and the BFS solver were implemented in OCaml. Experiments were conducted on a 250×250 grid with the start cell at the bottom-right corner and the goal at the top-left corner. Generation time per algorithm was measured as an average of 20 runs, repeated 50 times with different random seeds. Binary Tree had the fastest average generation time (0.0485 seconds), followed by Recursive Backtracking (0.1416 seconds), while Aldous-Broder was the slowest (4.2691 seconds). However, solving times showed a different pattern: Aldous-Broder produced mazes that were solved the fastest by BFS (0.0029 seconds), followed by Binary Tree (0.0089 seconds), with Recursive Backtracking yielding the longest solving time (0.0243 seconds). These findings indicate that no single algorithm dominates both metrics; the optimal choice depends on whether generation speed or solving speed is prioritized. The results support the hypothesis that Aldous-Broder's uniform spanning tree property leads to more efficiently solvable mazes despite its high generation cost.

Keywords: Maze generation; BFS; OCaml; performance comparison
Published: July 22, 2026
DOI: 10.54254/2753-8818/2026.PU35550
Volume: TNS Vol.175
pp. 73-79
Download PDF

References

  1. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009).Introduction to algorithms(3rd ed.). MIT Press.
  2. Boldovs, I., Vinogradovs, J., & Grabusts, P. (2016). Comparison of maze generation algorithms. InHET
  3. Vijaya, J., Gopu, A., Vinayak, K. V. S. G., Singh, T. J., & Malhotra, K. (2024). Analysis of maze generation algorithms. In2024 5th International Conference on Innovative Trends in Information Technology (ICITIIT)(pp. 1-6). IEEE.
  4. Aldous, D. (1990). The random walk construction of uniform spanning trees and uniform labelled trees.SIAM Journal on Discrete Mathematics, 3(4), 450–465.
  5. Broder, A. (1989). Generating random spanning trees. InProceedings of the 30th Annual Symposium on Foundations of Computer Science (FOCS)(pp. 442–447).
  6. Čarapina, M., Staničić, O., Dodig, I., & Cafuta, D. (2024). A comparative study of maze generation algorithms in a game-based mobile learning application for learning basic programming concepts.Algorithms, 17(9), 404.
  7. Zhang, H. (2025). Comparative implementation of binary tree and recursive backtracking maze generation algorithms in OCaml. InProceedings of the 2nd International Conference on Engineering Management, Information Technology and Intelligence (EMITI)(pp. 246–251). SciTePress.
  8. Wang, X. (2024). OCaml-based recursive backtracking and Aldous Broder algorithms in solving maze challenges.AIP Conference Proceedings, 3194(1), 050011.
  9. Wang, Q. (2024). Comparative analysis of maze solving algorithms based on OCaml.AIP Conference Proceedings, 3194(1), 040001.
  10. Dagaev, A. V., Sorokin, A. A., Kovalenko, R. A., & Yakovleva, E. A. (2020). Mazes creation for further study of swarm intelligence.IOP Conference Series: Materials Science and Engineering, 919(5), 052058.
  11. Erbil, M. E., Özkahraman, M., & Bayrakçı, H. C. (2025). Comprehensive performance analysis and evaluation of various maze solving algorithms for optimized autonomous navigation and pathfinding.Fırat University Journal of Engineering, 37(1), 151–166.