Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a working backtracking Sudoku algorithm.
Time Complexity
Assuming the board size is 9x9, the time complexity, expressed in Big O notation, would be O(9^(n^2)), where n represents the number of both sides of the Sudoku board. This is due to the nature of backtracking, which requires us to try numbers 1-9 in every cell of the grid in the worst-case scenario.
However, the actual time complexity could be significantly less, thanks to the pruning strategy implemented in the algorithm. This strategy ensures that we return as soon as the board is filled up
Space Complexity
If n is the number of both sides of the Sudoku board, then the space complexity would be n^2. This is because, in the worst-case scenario, with all cells empty, the entire grid would be loaded into memory during the recursive backtracking. Although we mutate the actual grid in place and do not create any extra memory for the grid, the additional space complexity arises from using the call stack during recursion.