Problem Definition
Place N queens on an N×N chessboard such that no two queens threaten each other. No two queens can share the same row, column, or diagonal.
Algorithm 1: Backtracking
Assigns one queen per column, left to right. For each column, tries every row. If no safe row exists, backtracks to the previous column and tries the next row.
Time: O(n!) · Space: O(n) · Trade-off: Simple but explores many dead-end branches
Algorithm 2: Forward Checking
Backtracking enhanced with constraint propagation. After placing each queen, immediately eliminates conflicting rows from all future columns’ domains. If any column’s domain becomes empty, backtracks immediately.
Time: O(n!) · Space: O(n²) · Trade-off: 58% fewer nodes but 3× overhead from domain copying
Algorithm 3: Minimum Conflicts (Local Search)
Starts with a random placement, then iteratively moves the most-conflicted queen to the row with fewest conflicts. Uses random restarts to escape local minima.
Time: O(n) avg · Space: O(n) · Trade-off: Probabilistic but remarkably fast in practice
Key Insight
Forward Checking explores 58% fewer nodes than Backtracking but runs 3× slower. The overhead of copying domain arrays at each step exceeds the search savings. This demonstrates that node count alone doesn’t predict real-world performance — the cost per node matters.