Search space representation and analysis of the backtracking algorithm for the N-Queens problem

Thanh Toan Lam1, , Van Chi Nguyen1, Xuan Ha Giang Nguyen1,  
1 Faculty of Information Technology, Cantho University of Technology, Vietnam

Main Article Content

Abstract

The N-Queens problem is a classical constraint satisfaction problem in artificial intelligence and combinatorial optimization. Although its formulation is simple, its search space grows rapidly as the board size increases, making exhaustive search computationally inefficient. This study analyzes the N-Queens problem within the search-space framework of the Backtracking algorithm, focusing on branching expansion, constraint checking, and early pruning of infeasible configurations. Three methods are implemented and compared: permutation-based exhaustive search, conventional Backtracking, and Bitmask Backtracking. Experimental results show that conventional Backtracking reduces the search workload from 40,320 permutations to 2,057 nodes for N=8, and from 3,628,800 permutations to 35,539 nodes for N=10. In addition, Bitmask Backtracking visits the same number of nodes as conventional Backtracking but achieves approximately 2.75× and 4.14× speed-up for N=8 and N=10, respectively. These results indicate that Backtracking improves efficiency through search-space pruning, while Bitmask representation further reduces the computational cost of constraint checking. The study provides a systematic and reproducible analysis of Backtracking for understanding constraint-based search and optimization problems.

Article Details

References

Bell, J., & Stevens, B. (2009). A survey of known results and research areas for the N-Queens problem. Discrete Mathematics, 309(1), 1–31. https://doi.org/10.1016/j.disc.2007.12.043
Gent, I. P., & Walsh, T. (1999). CSPLib: A benchmark library for constraints. In Proceedings of the 5th International Conference on Principles and Practice of Constraint Programming (CP'99) (pp. 480–481). Springer.
Haralick, R. M., & Elliott, G. L. (1980). Increasing tree search efficiency for constraint satisfaction problems. Artificial Intelligence, 14(3), 263–313. https://doi.org/10.1016/0004-3702(80)90051-X
Kumar, V. (1992). Algorithms for constraint-satisfaction problems: A survey. AI Magazine, 13(1), 32–44. https://doi.org/10.1609/aimag.v13i1.976
Lijo, V. P., & Jose, J. T. (2015). Solving N-Queen problem by prediction. International Journal of Computer Science and Information Technologies, 6(4), 3844–3848.
Poole, D. L., & Mackworth, A. K. (2023). Artificial Intelligence: Foundations of Computational Agents (3rd ed.). Cambridge University Press.
Russell, S. J., & Norvig, P. (2020). Artificial intelligence: A modern approach (4th ed.). Pearson.
Schaefer, T. J. (1978). The complexity of satisfiability problems. In Proceedings of the 10th Annual ACM Symposium on Theory of Computing (pp. 216–226). ACM. https://doi.org/10.1145/800133.804350
Simonis, H. (2005). Sudoku as a constraint problem. In Proceedings of the CP Workshop on Modelling and Reformulating Constraint Satisfaction Problems (pp. 13–27).
Thada, V., & Dhaka, S. (2014). Performance analysis of N-Queen problem using backtracking and genetic algorithm techniques. International Journal of Computer Applications, 102(7), 26–29. https://doi.org/10.5120/17891-8867
Tsang, E. (1993). Foundations of constraint satisfaction. Academic Press.
Wu, Q., & Tian, Y. (2018). An improved backtracking algorithm for solving N-Queens problem. In Advances in Intelligent Systems Research (Vol. 157, pp. 101–105). Atlantis Press. https://doi.org/10.2991/emehss-18.2018.21