Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Samuel Adeoye - Sudoku Algorithm #88

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

sam-ayo
Copy link

@sam-ayo sam-ayo commented Jan 23, 2024

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.

@sam-ayo sam-ayo changed the title Sudoku Algorithm Samuel Adeoye - Sudoku Algorithm Jan 23, 2024
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