Skip to content

Conversation

@Raghu0703
Copy link

Description

This PR adds a Sudoku Solver implementation using the Backtracking algorithm as requested in issue #6929.

Changes

  • Added SudokuSolver.java in src/main/java/com/thealgorithms/backtracking/

    • Implements backtracking algorithm to solve 9×9 Sudoku puzzles
    • Includes isValid() method to verify Sudoku constraints (row, column, 3×3 subgrid)
    • Includes solveSudoku() method with recursive backtracking logic
    • Includes printBoard() helper method for formatted output
    • Provides example usage in main() method
  • Added SudokuSolverTest.java in src/test/java/com/thealgorithms/backtracking/

    • Tests solvable Sudoku puzzle with expected solution verification
    • Tests unsolvable Sudoku puzzle (invalid constraints)
    • Tests already solved Sudoku
    • Tests empty Sudoku board
    • Tests difficult Sudoku puzzle with fewer clues

Algorithm Details

Testing

✅ All new tests pass: mvn test -Dtest=SudokuSolverTest
✅ Verified with multiple Sudoku puzzles
✅ Code follows repository formatting standards
✅ Includes proper documentation and comments

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL

- Implements Kruskal's algorithm using Union-Find
- Includes comprehensive unit tests
- Time complexity: O(E log E)
- Space complexity: O(V + E)

Fixes TheAlgorithms#7067
- Implements backtracking algorithm to solve 9x9 Sudoku puzzles
- Includes isValid() method to check Sudoku constraints
- Includes solveSudoku() method with recursive backtracking
- Adds comprehensive unit tests covering multiple scenarios
- Tests include solvable, unsolvable, empty, and difficult puzzles
- Includes example usage in main method with formatted output
- Documents time complexity O(9^m) and space complexity O(m)

Fixes TheAlgorithms#6929
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant