Comparative Analysis of the Performance Testing Results of the Backtracking and Genetics Algorithm in Solving Sudoku Games

Games that hone thinking skills and logical accuracy have recently been very popular. One of them is the game Sudoku. Sudoku is a game that hones logic through puzzles arranged in rows and columns. Sudoku is also defined as a puzzle game that aims to arrange several numbers in a grid from one to nine on a grid consisting of 9x9 squares. The concept of this Sudoku game is to enter numbers into the rows and columns provided. The rule of this game is that the numbers arranged on the board cannot be the same in every row, column, and 3x3 square in the grid. In another sense, each number entered must appear once in each row and column. When running Sudoku, several numbers are already instructions for players to fill in the next boxes. The number of clues at the beginning of the game determines the difficulty level players face. The fewer clues, the more difficult the Sudoku is to solve. This study aims to compare how to solve Sudoku using genetic algorithms, backtracking, and the completion time needed. The tests' results show that the genetic and backtracking algorithms can solve Sudoku games quickly. Still, the backtracking algorithm has the advantage of being relatively shorter, and the process is not so complicated that the backtracking algorithm can be an alternative solution to solving Sudoku logic games.


I. INTRODUCTION
A puzzle game is a game that requires logic and proper reasoning to solve problems involving logic.Currently, there are many types of puzzle games and riddles.Of the many puzzle games, one of them is a number puzzle.A well-known number puzzle game is Sudoku.Sudoku itself is a number puzzle game originating in Japan [1].How to use Sudoku is played on a board consisting of 9 squares where each box has a subgrid with a size of 3×3.Sudoku is a numbers game where players must fill in several available empty boxes using random numbers from 1 to 9 [2].At the beginning of this Sudoku game, several random numbers from 1 to 9 and boxes serve as clues to solve Sudoku puzzles.The player's task is to complete other empty or unfilled squares to fill the entire Sudoku board with numbers [3].When viewed from the game's rules, this Sudoku has simple rules, requiring players to fill in an empty box with random numbers.However, even though it is simple in terms of the rules, it turns out that many players cannot complete it.
Several algorithms are used to solve Sudoku games, including genetics and backtracking.A genetic algorithm is an algorithm for searching based on the mechanism of natural selection and genetics.The genetic algorithm can be used as a very precise algorithm to solve complex optimization problems that cannot be solved using conventional methods [4].While the backtracking algorithm is a revision of the brute-force algorithm and the exhaustive-search algorithm, in which this algorithm builds a statespace tree to find a solution [5].The concept of this backtracking algorithm is to work recursively in finding a solution to a problem with several possible solutions [6].
Several previous studies that discussed using genetic algorithms and backtracking in artificial intelligence problems, especially Sudoku games, included [7] research on how to solve Sudoku using brute force and backtracking algorithms.Then [8] describes solving Android-based Sudoku puzzles with the backtracking algorithm.Research conducted by [9] discusses the steps for completing the 9x9 Su Doku Pattern using backtracking.Research from [10] is related to the discussion of how genetic algorithms can help solve Sudoku puzzle logic problems.This study aims to analyze the results of comparing how to solve logical Sudoku puzzles between genetic algorithms and backtracking.The analysis was carried out regarding the complexity of the processing speed between the two algorithms used.This comparison aims to produce the best algorithmic solution for solving Sudoku games based on the solving steps' performance, speed, and complexity.

A. Data Collection Techniques
Data collection techniques are part of finding reference sources needed to support research.In this study, a literature study is used to find reference sources.A literature study is a data collection technique by conducting surveys and investigations on existing documents and journals regarding potato plants.Reference books can also be used as a guide in the system development process.

B. Backtracking Algorithm
The backtracking algorithm is one of the algorithms in dynamically finding solutions to the state space tree based on the Depth First Search (DFS) algorithm.The backtracking algorithm will trace possible numbers that only lead to a solution or settlement.A settlement or solution can be found with a few traces and is efficient because it does not examine all possible existing settlement numbers [11].Fig. 1 shows an example of a state space tree of the backtracking algorithm [12].Based on Fig. 1, the search process begins by visiting node 1 to node 4. If the destination to be searched has not been found, the next process is to continue the search to one of the previous branches (node 2 to node 3) and go down if there are still other branches.The process is carried out iteratively until the final destination is obtained (node 1 to node 5).With this backtracking method, the search process leads to only one solution, which does not lead to all possible solutions.This situation makes the search time with backtracking less so that the time needed is effective and efficient.In general, the completion steps in this backtracking algorithm (1) [13] are as follows [5] : a) The form of finding a solution is a path from roots to leaves.The resulting node is called a live node, and the expanded live node is called an E-node (Expand node).b) If the expansion of node E forms a path that does not lead to a solution, then that node will become a dead node that cannot be expanded anymore.c) If the last position is located at a dead node, then the search process is carried out by generating other child nodes, and if there are no child nodes, then tracing back to the parent node.d) The search process will stop if a solution has been found or no live nodes can be found.
Algorithm (1).Backtracking Algorithm Backtrack procedure (input k:integer) { Looking for all solutions with backtracking method Input : k, that is index of component vector x

C. Genetic Algorithm
A genetic algorithm is a method for solving optimization problems based on natural selection, namely techniques that follow the evolution and development of biology [14].Simultaneously the genetic algorithm evaluates several points in space.The genetic algorithm has a natural evolutionary process includes population, inheritance, mutation, crossover, and selection [15].
In designing a Sudoku puzzle game with a genetic algorithm, several candidate solutions for each puzzle box are first sought before entering the process.The goal of this process is to eliminate the unlikely solution candidates.For example, if a box is filled with the number 9, then the number 9 is eliminated from the candidates in the boxes in the same row, column, or region.This step aims to make the genetic algorithm have good convergence.The solution to a puzzle is obtained when a chromosome has a perfect fitness value because a chromosome with a fitness value below the perfect fitness value is not a solution to a Sudoku puzzle.In the genetic algorithm, one chromosome is a candidate solution to the puzzle.Because the possible values in the solution are between 1 and 9, the chromosome representation is a series of integer numbers with the chromosome length according to the number of empty squares in the puzzle.The fitness value is obtained from the chromosome length minus the number of error genes.An error gene is a gene that contains numbers that appear multiple times in a row, column, or region.

D. Definition of Puzzle
Puzzles are pieces of images that can be shaped or arranged to form one unified picture.From its shape, Puzzle media can be categorized as picture-learning media.Puzzles can be played by all groups, from children to adults.By playing puzzles, children can learn to be thorough and train children's memory.This puzzle game can be played anywhere at school, home, or elsewhere [16].
A puzzle game is a game that has pieces of images with a level of difficulty that adjusts the child's development.Puzzles are a form of play that requires precision and trains children to concentrate because they have to concentrate when assembling puzzle pieces to form a complete and complete picture as a whole [17].

E. Sudoku puzzles
Sudoku Puzzle is a fun and simple educational game that can attract students' attention in the learning process in the classroom.Sudoku has advantages, including developing ways of reasoning and thinking correctly according to logic.Sudoku generally uses numbers one through nine, arranged in a 9 × 9 grid divided into 3 × 3 squares called subgrids.The game Sudoku Puzzles requires players to use brain power and concentration in problem-solving strategies [18].
Sudoku is a puzzle game consisting of a grid of 81 squares arranged in 9 rows and 9 columns.In the Sudoku grid itself, some subgrids are 3x3 in size.In the Sudoku game, players are asked to fill in each box with one number, namely the numbers 1 to 9, so that each box has a unique number for each row, column, and subgrid on the board.The difficulty level of the Sudoku game is measured by the number of clues on the grid at the start of the game.The fewer clues on the grid, the more difficult the Sudoku will be to solve.

III. RESULT AND DISCUSSION
This section will explain how to solve the Sudoku math puzzle game using backtracking and genetic algorithms.The Sudoku puzzle model used is a 9x9 grid size.The pseudocode for the Sudoku solution is shown in the algorithm (2).

A. Analysis of Solving Sudoku with the Backtracking Algorithm
In general, solving Sudoku puzzles can be done manually using the following techniques : 1) Scan.Performs a row or column scan to identify which row contains certain numbers.This process is then repeated for each column (or row) systematically.2) Marking.It is a process of logical analysis by marking candidate numbers that can be put in a box.3) Analysis.The process of eliminating candidates, where progress is made by eliminating or deleting candidate numbers consecutively until one box contains only one candidate.In particular, the application of the Backtracking algorithm in the Sudoku logic game is as follows: a) The process starts from the first row and first column matrix elements b) Check all possible numbers that the row can own c) If there is a valid number with the constraints of the Sudoku game, proceed with checking the next element of the matrix.d) If no valid numbers are found, backtrack to the previous matrix elements.
e) The process stops when it has found a solution or if there is no possibility of a solution.The process of testing the backtracking algorithm in solving this puzzle is carried out in several 10 Sudoku puzzles with different levels of difficulty or game level.The test results are shown in Table I.I shows the results of the trial process of the sudoku program on 10 puzzles that have different levels of difficulty.The number of empty boxes in each test is set from 43-45 empty boxes.In this experiment, the analysis was carried out on the side of the completion time and the number of backtracking processes.Based on the results in Table 1, it can be concluded that if there are many empty squares in the puzzle, not all are directly proportional to the increase in time and the amount of backtracking.Fig. 5 shows a graph of the backtracking test according to the data in Table I.To calculate the average Sudoku completion time with the backtracking algorithm, you can use the following Equation (1).
Where the y variable is the average completion time, the x variable is the time required (ms), and the s variable is the number of trials, so from the above Equation, the average value can be calculated using Equation (2).ms y The graph in Fig. 5 shows the time the program needs to complete the Sudoku Puzzle from the tests carried out in this study.The time parameter in this test uses units of microseconds (ms).This was done to see the difference in time between tests with empty boxes and different numbers.The graphs and test data show that the 7th and 9th tests have a more prominent completion time than the others.This happened because the two tests had a higher difficulty than the other 8 tests.

B. Analysis of Solving Sudoku with Genetic Algorithms
The following procedures need to be carried out to use a genetic algorithm to solve a Sudoku puzzle: 1. Convert the values in the cell into the genes that will form the chromosomes.The conversion process uses decimal encoding because it resembles the values in a cell where an empty cell will be converted to gene 0, and a cell with a value will immediately take its value as a gene.An example is based on Fig. 6.  (2) 5.After calculating the fitness value, the chromosomes will be sorted starting from the fitness with the smallest value because the smaller the fitness value, the worse the genes in the chromosome.6.After sorting, mutations are carried out on the chromosomes according to that sequence.There are two types of mutations, Gene mutations and Swap mutations.Gene mutations are carried out as long as they are not stuck, while swap mutations are carried out on the gene of a chromosome with the highest mutation frequency.The gene will be exchanged with another randomly selected gene.7. When the mutation is complete, the fitness calculation will repeat until it produces a solution.That is, each gene in the chromosome does not have the same gene in the chromosome.The pseudocode of the genetic algorithm in the Sudoku game is shown as algorithm (3).
Algorithm (3) Based on the pseudocode shown above, it will be used to test the algorithm in a Sudoku game, which can only be finished when all the cells contain nothing.The blank cell test was performed 10 times sequentially on a 9x9 Sudoku model.The test results were carried out in mild and severe case conditions.The test results in the form of information on the length of time used are shown in Table II.From the two examples of tests carried out, it can be concluded that the completion process using this genetic algorithm goes through several stages to obtain the maximum result or solution with the least number of genes.

Fig. 1 .
Fig.1.Example of a Backtracking Algorithm State Space Tree

Fig. 6 .
Fig. 6.Chromosome Encoding Decimal 0320 2. The results of the formation of these chromosomes represent each row, column, and region so that the genes on the chromosomes are more directed when optimized.For example, based on Fig.7.

Fig. 7 .
Fig. 7. Chromosome Representation Picture 3.After the chromosomes are generated, assigning the initial value of the gene to the chromosome with a value of 0 is carried out by randomizing the gene.For example, a chromosome has the 0230 gene.After initialization, it produces 1234.4. Next is to calculate the fitness value for each chromosome using Equation (2).

TABLE I TESTING
RESULTS OF 10 SUDOKU PUZZLES USING THE BACKTRACKING ALGORITHM Process Testing to 33DOI: http://dx.doi.org/10.25139/ijair.v5i1.6501Table . The Genetic Algorithm In The Sudoku Game