Of late, I have solved a few problems using backtracking(Sudoku solver, N Queens problem). While I can intuitively understand that backtracking is better than brute force, I am unable to reason it out mathematically/asymptotically. For instance, say we are implementing a sudoku solver for a N * N grid, where there are K empty slots to be filled. Here:
- There are NK end states of the N * N grid.
- At the end of filling each slot, we check if it's still valid and this validation takes O(N) time.
[A brute force approach would be to fill out all K slots using any of the N digits and then checking that the final state is a valid grid.]
In all, we reason that it takes O(NK*NK) = O(KNK+1)
Well, that is a fair enough bound for the brute force algorithm, but in a backtracking algorithm, we prune out a lot of the invalid states much, much earlier in the filling process. Clearly, the backtracking algorithm is very fast in practise, compared to the brute force implementation. I searched for similar questions and found this one, but it uses the same bounds as the brute force. How can we asymptotically prove that this backtracking algorithm is better than the brute force algorithm?
EDIT: Since people are voting to close this question as "Too-Broad", I am iterating that I am looking for the specific case of the aforementioned Sudoku solver only. You can however, share any ideas that you usually use to reason out asymptotically that a given backtracking problem is faster than a brute force approach.