Research Article

A Comparative Study of BFS and Left-Hand Wall-Following Algorithms for Maze Solving in OCaml

Jiajie Yuan*
Nanjing Tech University

* Corresponding author: [email protected]

Abstract

This paper aims to investigate and solve maze-solving problems by implementing the Breadth-First Search (BFS) algorithm and the Left-Hand Wall-Following algorithm, providing references for maze navigation of small embedded robots. In this study, the OCaml programming language is adopted. This paper implements both the BFS and Left-Hand Wall-Following algorithms to solve three mazes of different sizes (30×28, 30×17, 30×16). The total moving steps and the shortest valid paths are recorded. The time and space complexity of the two algorithms are calculated, and comparative tables are generated for analysis. Experiments show that the Left-Hand Wall-Following algorithm has a constant space complexity of O(1) with stable memory consumption. However, its generated path length can reach 2.5 to 10 times the theoretical shortest path, and it is only applicable to simple mazes. In contrast, BFS can stably output globally optimal paths and adapt to all types of complex mazes, yet its memory overhead grows linearly with maze size. The two algorithms fit distinct application scenarios and can be selected flexibly according to equipment memory constraints and requirements for optimal paths.

Keywords: Maze solving; BFS algorithm; Left-hand wall-following algorithm
Published: July 28, 2026
DOI: 10.54254/2753-8818/2026.PU35704
Volume: TNS Vol.185
pp. 1-6
Download PDF

References

  1. Dwivedy, S., & Gupta, S. K. (2016). A comparative study of BFS and DFS for autonomous exploration of unknown environments.International Journal of Robotics and Automation, 31(1), 68–76.
  2. Moore, E. F. (1959). The shortest path through a maze. InProceedings of the International Symposium on the Theory of Switching Circuits(pp. 285–292). Harvard University Press.
  3. Patle, B. K., Babu, L. G., Pandey, A., Parhi, D. R., & Jagadeesh, A. (2019). A review: On path planning strategies for navigation of mobile robot.Defence Technology, 15, 582–606.
  4. Bhattacharya, S., & Ghosh, A. (2018). Breadth-first search and its diversified real-world applications.International Journal of Computer Applications, 180(47), 1–7.
  5. Skiena, S. S. (2008).The algorithm design manual(2nd ed.). Springer.
  6. Elkari, B., Oubah, L., & Sekkat, H. (2024). Exploring maze navigation: A comparative study of DFS, BFS, and A* search algorithms.Statistics, Optimization and Information Computing, 12(3), 761–781.
  7. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009).Introduction to algorithms(3rd ed.). MIT Press.
  8. Koenig, S., & Likhachev, M. (2004). Lifelong planning A*.Artificial Intelligence, 155(1–2), 93–146.
  9. Leroy, X., Doligez, D., Frisch, A., Garrigue, J., Rémy, D., Sivaramakrishnan, K. C., & Vouillon, J. (2024).The OCaml system release 5.2: Documentation and user's manual(Doctoral dissertation, Inria).
  10. Wei, X., & Li, M. (2024). Comparative analysis of maze solving algorithms based on OCaml. InAIP Conference Proceedings (Vol. 3194, No. 1, Article 040001). AIP Publishing.
  11. Del Rosario, J. (2013). Modelling and characterization of a maze-solving mobile robot using wall follower algorithm.International Journal of Advanced Research in Computer Science and Software Engineering, 3(7), 771–776.
  12. Saman, A. B. S., & Abdramane, I. (2013). Solving a reconfigurable maze using hybrid wall follower algorithm.International Journal of Computer Applications, 82(3), 10–14.
  13. Mazumdar, S., & Roy, S. (2020). Performance comparison robot path finding uses flood fill-wall follower algorithm.International Journal of Robotics and Automation, 5(1), 22–28.
  14. Rahman, M. (2025). A comparative study of maze-solving algorithms: Performance, complexity, and practical applications in AI and robotics.Journal of Artificial Intelligence Research, 12(2), 89–102.