2

The backtracking approach for n-queens is clearly O(n!). However I am looking at these links here: https://algodaily.com/challenges/classical-n-queen-problem

https://www.geeksforgeeks.org/n-queen-problem-backtracking-3/

They give O(n^2) time complexity. How is that the case? I read their code, and their solutions appear to be O(n!). For each row, try all columns. That's n*(n-1)*(n-2)... etc I have no idea how they're getting O(n^2).

JobHunter69
  • 1,706
  • 5
  • 25
  • 49

0 Answers0