Sudoku Solver Report
Sudoku Solver Report
1. Introduction
This report documents the implementation of an AI-based Sudoku solver using constraint
satisfaction and backtracking search algorithms. The solver is designed to efficiently solve 9×9
Sudoku puzzles of varying difficulty levels while adhering to the constraints that each number
from 1 to 9 must appear exactly once in each row, column, and 3×3 sub-grid.
2. Algorithm Design
The solver implements a constraint satisfaction problem (CSP) approach with the following
components:
The core algorithm combines backtracking search with several optimization heuristics:
1. Minimum Remaining Values (MRV) Always selects the cell with the fewest possible values
first
2. Forward Checking Eliminates invalid values from related cells when a value is assigned
3. Constraint Propagation Reduces domains of unassigned variables based on current
assignments
3. Implementation Details
1. find_possible_values() Calculates valid numbers for a cell by eliminating values that appear in
the same row, column, or 3×3 box
2. backtrack() Recursive function that implements the backtracking search with forward
checking
3. Constraint Propagation Implemented through immediate elimination of invalid values when a
cell is assigned
4. Optimization Techniques
1. Efficient Data Structures Uses NumPy arrays for fast grid operations and set operations for
constraint checking
2. Early Termination Detects unsolvable states immediately when any cell has no valid values
3. Heuristic Ordering Processes most constrained cells first to minimize branching
4. Forward Checking Maintains consistency by updating possible values after each assignment
5. Performance Analysis
6. Testing Methodology
1. Unit Tests Verified correct solution for the first very easy puzzle
2. Edge Cases Tested with empty grids and completely filled grids
3. Invalid Puzzles Correctly identifies and handles unsolvable configurations
4. Difficulty Scaling Performance evaluated across all difficulty levels
8. Conclusion
The implemented Sudoku solver successfully combines constraint satisfaction techniques with
heuristic search to efficiently solve Sudoku puzzles. The use of MRV heuristic and forward
checking provides significant performance improvements over naive backtracking. While
optimized for the standard 9×9 Sudoku, the architecture could be extended to larger or variant
Sudoku puzzles with minimal modifications.
9. Future Improvements
This implementation meets all requirements specified in the assignment and provides a robust
foundation for solving Sudoku puzzles of varying difficulty levels.