Comparison Analysis of Breadth First Search and Depth Limited Search Algorithms in Sudoku Game

Received Dec 13, 2021 Revised Dec 20, 2021 Accepted Dec 30, 2021 Sudoku is a game that sharpens the brain and is very well known. But the problem faced in this condition is how we can find a solution for the completion of this game. Problems with the Sudoku game can be solved by using the concept of Artificial Intelligence (AI). Some of the algorithms that can be used are the Breadth First Search (BFS) and Depth Limited Search (DLS) algorithms. The purpose of this research is to find a solution for Sudoku and make a comparative analysis of the search results of the two algorithms. The results obtained are application design in the form of a simulation of the completion of the Sudoku game problem with two algorithms. And it has been proven from the two algorithms that DLS is more efficient and faster than BFS. While BFS itself has advantages, in terms of a more structured and systematic search system that is able to find all possible numbers in each box. In this case, if a Sudoku question has more than one answer, then BFS will find it.


INTRODUCTION
Artificial Intelligence (AI) is a part of computer science that studies how to make computers do jobs like and as well as humans do. At the beginning of its creation, the computer only functioned as a calculating tool. But along with the times, computer technology is increasingly being improved and until now AI is often used to find solutions or solutions [1], [2]. In the case of AI there is a space that contains all the states which can be called a state space. Conditions in the state space include: start state, goal state is a solution that is reached and needs to be checked whether it has reached the target, rules or rules that provide limitations on how to change a state into another state. The state is represented as a node, while the allowed steps or actions are represented by arcs [3], [4].
One of the popular puzzle games originating from Japan is Sudoku. Sudoku consists of 81 squares consisting of 9 columns and 9 rows. The big box is further divided into 9 partial squares, each of which consists of 3 x 3 squares (see Figure 1). Players may fill the boxes with numbers from 1 to 9. The condition is that there must be no repetition of numbers in one column, also in one row, and in any 3 x 3 partial box. As a starting point, some of the boxes have been filled with opening numbers. Players are welcome to continue. Unlike other number games, Sudoku does not train arithmetic intelligence (the ability to add or subtract numbers), but Sudoku trains players' logical intelligence to complete Sudoku by filling all the boxes without violating the existing rules. A good Sudoku problem is one that only has exactly one answer. Sudoku is a puzzle game that deals with space and circumstances. In AI there are several search techniques, such as the Breadth First Search (BFS) and Depth Limited Search (DLS) algorithms [2], [4], [5]. The Breadth First Search (BFS) algorithm is a search that broadens the solution space systematically and explores all the possibilities that exist at each level. And the Depth Limited Search (DLS) algorithm is a search that is carried out from the initial node in depth until the most recent node is found.
The advantage of the BFS algorithm is that there is no deadlock, if there is one solution then BFS will find it, and if there is more than one solution then the minimum solution will be found. The disadvantage is that it requires a lot of memory, because it stores all nodes in one tree, and it takes quite a long time, because it will test n levels to get a solution at the (n + 1) level. For more details, consider the illustration of BFS in Figure 2. The advantage of the DLS algorithm is that it quickly reaches the depth of the search space. If it is known that the path to the solution of the problem will be long then DLS will not waste time performing a large number of 'shallow' states in the graph/tree problem. DLS is much more efficient for search space with multiple branches because it doesn't need to evaluate all nodes at a certain level in the open list. In addition, DLS requires relatively small memory because only the nodes on the active path are stored. The disadvantage is that before use, it must be known what the maximum level of a solution is. If the depth limit is too small than the solution depth level, then DLS cannot find the existing solution. That is, DLS can be incomplete if the depth limit is smaller than the solution level. For more details, consider the illustration of DLS in Figure 3. This research will create software that can be used to find solutions for the Sudoku game using BFS and DLS. In addition, a comparative analysis will be made regarding the time required to obtain a solution and the number of nodes stored and developed by these two algorithms.

RESEARCH METHOD
Research methods are divided into:

2) Analysis Methods
Methods The analysis is carried out with the BFS and DLS algorithms [1], [3], [22], [23], [24], [25], [26], [27], [28], [29]. BFS is a search that is carried out by visiting each node systematically at each level until the goal state is found. Or in other words, a search that is carried out by visiting nodes at the same level so that the goal state is found [30], [31], [32], [33]. DLS is carried out from the initial node in depth to the most recent (dead-end) or until a solution is found. In other words, the branch or child node that is visited first. DLS limits the maximum level of a solution [34], [35], [36], [37], [38], [39], [40].
The detailed research method can be seen in Figure 4.

BFS to Complete Sudoku game
The process of finding Sudoku answers using the BFS is as follows [4], [7], [22], [41], [42]: 1) Search starts from an empty root node 2) From this root node, all possible numbers that can be entered in box-0 are developed without violating the Sudoku rules. Each of these possible numbers is entered into a single node at level-0. 3) If the next box is a Sudoku question box (a number that cannot be changed when working on a Sudoku problem), then the parent node does not need to develop child nodes and all parent nodes have the same child node, namely the node that contains the numbers in the question box. 4) Meanwhile, if the next box is the answer box, then develop all possible numbers that can be entered in the box without violating the Sudoku rules. 5) Continue developing and searching for nodes until level 80 is reached. The answer is a series of steps from node level-0 to node level-80. 6) If none of the nodes can reach the 80th level, then it is certain that the Sudoku problem has no solution. Figure 6. Sudoku game answer search process using BFS Figure 6 shows that the search starts from an empty root node. The BFS lookup then looks for all possible numbers that can be placed in Box-0 and those numbers are 4, 6 and 7. These numbers are then entered in the Level-0 child nodes. Then, the search and development of the node continues on the leftmost Level-0 node which contains the number 4. Because the next box (Box-1) is a Sudoku game question that cannot be changed its value, the Level-1 child node is not developed and is filled in immediately. by the number in Box-2, which is number 1. This also happens to other Level-1 nodes. The search then continues on the Level-1 node, from the leftmost node to the rightmost node and continues for nodes at the next level. If the BFS quest reaches the node-80, the Sudoku game answer has been found. However, if the BFS search does not find a way to reach node-80, then it is certain that the Sudoku game question does not have an answer.
2) From the root node, 1 possible number will be developed that can be entered in box-0 and does not violate the Sudoku rules. This number is a level-1 child node. Furthermore, the child nodes are developed from level-1, and so on. 3) If no child nodes can be expanded, because all numbers violate Sudoku rules, then backtrack to the parent node and develop another child node. 4) If the next box is a Sudoku problem (a number that cannot be changed when working on a Sudoku problem), then the parent node does not need to develop a child node and goes directly to the child node containing the Sudoku question and develops other child nodes. 5) Continue searching and expanding nodes until you reach the 80th level node. Sudoku's answer is a series of steps from node level-1 to node level-80. 6) If there is a backtrack on the root node, it can be ascertained that the Sudoku question does not have an answer. Figure 7. Sudoku game answer search process using DLS  Figure 7 shows that the search starts from the root node. The DLS search expands the Level-0 child node (Square-0) and tries to enter the first number from 1-9 which does not violate the rules of the Sudoku game. The number in question is number 4, so number 4 is placed in Box-0 or Level-0 node and traces that node. Then, the search develops child nodes of Level-0 nodes, namely Level-1 nodes. However, because Box-1 contains an immutable Sudoku game problem, the Level-1 node is immediately occupied by the number 1. The development of the child nodes continues at the Level-1 node. It turns out that no numbers can be placed on the Level-2 nodes because all placements of numbers 1-9 violate the rules of the Sudoku game. Therefore, the search returns (backtrack) from the Level-1 node to the Level-0 node. A search on the level-0 node cannot develop any other child nodes other than the number 1, because the level-1 node is a Sudoku game problem box. Therefore, the search backtracks again to the root node. On the root node, the search develops another child node. The next number that does not violate the rules of the Sudoku game is number 6. Place the number 6 on the Level-0 node and trace the node. The search develops a child node from the Level-0 node, namely the Level-1 node that contains the Sudoku game problem, namely number 1. Search for the node. Next, the search expands the child nodes of the Level-1 node and returns a node with the number 4 (because numbers 1, 2 and 3 violate the rules of the Sudoku game). The search traces the Level-2 node and continues on the next nodes. The answer is found when the search node reaches the Level-80 node. However, if there is a backtrack to the root node, it can be ascertained that the Sudoku game question does not have an answer.
The results of the search with BFS and DLS to find the Sudoku answer to the question in Figure 5 can be seen in Figure 8. We will compare the number of nodes developed and the time it takes for the two algorithms to come up with an answer for the Sudoku game. This comparison is done by testing the 3 questions that have been previously stored. The details can be seen in Table 1. possible number to the next and so on until all boxes are filled with numbers. If no number can be placed in an answer box because it violates the rules of permaSudoku, then DLS will backtrack to the previous box and change the number in the box with another number, before advancing again to the next box.
Because the number of nodes developed by BFS search for answers is more and more wasteful than DLS search, DLS search finds Sudoku game answers faster than BFS search. BFS has an advantage, in terms of a more structured and systematic search system that is able to find all possible numbers in each box. In this case, if a Sudoku game question has more than one answer, then BFS will find it. DLS search proved to be better than BFS search in the number of nodes required and the time it took to find Sudoku game answers.

CONCLUSION
After conducting the analysis, several conclusions can be drawn as follows: 1) In theory in the case of Sudoku game completion, DLS is more efficient and faster than BFS. While BFS has an advantage, in terms of a more structured and systematic search system that is able to find all possible numbers in each box. In this case, if a Sudoku game question has more than one answer, then BFS will find it. 2) Meanwhile, in the problems that have been searched for solutions, not all questions can be solved with these two algorithms or can not find answers.
3) The drawback of this research is that it is only limited to 3x3 levels for the Sudoku game, so we can add several existing levels, namely 6x6, 8x8, 12x12. Can also use Heuristic algorithms, A* algorithms, and others.