Penggunaan algoritma Backtracking untuk Penyelesaian Masalah N-Queens: Studi Perbandingan Iteratif dan Rekursif - Rachmat Adiaz Arrofi; M.Erlangga Fauzi; Tata Sutabri (LPPM Sekolah Tinggi Ilmu Ekonomi - Studi Ekonomi Modern, 2025)
The N-Queens problem is a classic problem in computer science that requires the placement of N queens on an NxN chessboard without attacking each other. One of the common algorithmic approaches used to solve this problem is the backtracking algorithm, which is a technique for finding solutions by systematically trying all possibilities and backtracking when reaching a dead end. This study compares two implementation methods of the backtracking algorithm, namely the recursive and iterative approaches, in the context of solving the N-Queens problem. The focus of this study is to analyze the performance of the two approaches based on execution time, memory efficiency, and program code complexity. Experiments were conducted on various board sizes (N=4 to N=20) using the Python programming language. The test results show that the recursive approach has a simpler and easier-to-understand code structure, but is susceptible to stack overflow at large N values. Meanwhile, the iterative approach is more complex in its implementation, but tends to be more stable and efficient in the use of computer resources. This study contributes to a comparative understanding of the two approaches, as well as being a reference in choosing the right programming strategy to solve other combinatorial problems.