Skip to content

Commit 3169178

Browse files
committed
Add Sudoku Solver using Backtracking algorithm - Implements depth-first backtracking to solve 9×9 Sudoku puzzles - Includes validation for rows, columns, and 3×3 subgrids - Provides clean, modular implementation with helper methods - Includes comprehensive unit tests for solvable and unsolvable cases - Time Complexity: O(9^(n²)) in worst case - Space Complexity: O(n²) for recursion stack
1 parent 00a3b29 commit 3169178

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/test/java/com/thealgorithms/backtracking/SudokuSolverTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public void testSolvableSudoku() {
2020
{0, 0, 0, 0, 8, 0, 0, 7, 9}
2121
};
2222

23-
assertTrue(SudokuSolver.solveSudoku(board), "Sudoku should be solvable");
23+
assertTrue(SudokuSolver.solveSudoku(board),
24+
"Sudoku should be solvable");
2425
assertBoardValid(board);
2526
}
2627

@@ -38,7 +39,8 @@ public void testUnsolvableSudoku() {
3839
{0, 0, 0, 0, 8, 0, 0, 7, 9}
3940
};
4041

41-
assertFalse(SudokuSolver.solveSudoku(board), "Sudoku should not be solvable");
42+
assertFalse(SudokuSolver.solveSudoku(board),
43+
"Sudoku should not be solvable");
4244
}
4345

4446
@Test
@@ -56,7 +58,7 @@ public void testCompleteBoard() {
5658
};
5759

5860
assertTrue(SudokuSolver.solveSudoku(board),
59-
"Already solved Sudoku should return true");
61+
"Already solved Sudoku should return true");
6062
assertBoardValid(board);
6163
}
6264

0 commit comments

Comments
 (0)