Writing a Recursive Function for Placing n Queens on an n x n Chessboard

Click For Summary
SUMMARY

The discussion centers on writing a recursive function to place n Queens on an n x n chessboard, a common algorithmic challenge in computer science. The participant seeks to extend their solution to find all possible configurations where no two Queens threaten each other. The complexity of this task is highlighted, as it involves exponential growth in possible configurations as n increases. A reference link to a resource on the n Queens problem is provided for further exploration.

PREREQUISITES
  • Understanding of recursive programming techniques
  • Familiarity with backtracking algorithms
  • Basic knowledge of chess rules regarding Queen movements
  • Proficiency in a programming language capable of recursion (e.g., Python, Java)
NEXT STEPS
  • Implement a backtracking algorithm to solve the n Queens problem
  • Explore the concept of recursion in depth, focusing on base cases and recursive cases
  • Research optimization techniques for reducing the search space in recursive solutions
  • Study the mathematical foundations of combinatorial problems related to n Queens
USEFUL FOR

Computer science students, software developers, and anyone interested in algorithm design and optimization techniques, particularly in recursive problem-solving contexts.

discoverer02
Messages
138
Reaction score
1
I have an assignment to write a recursive function that will safely place n Queens on an n x n chessboard. This wasn't all that difficult to figure out.

For extra credit I'm supposed to write another function(s) (recursive?) that figures out all the possible solutions. This is, so far, giving me fits.

Any nudge in the right direction would be greatly appreciated.
 
Last edited:
Computer science news on Phys.org
Can you be a little more specific in what you mean by figure out all the possible solutions? Do you mean once you place all the queens on the board, find all the possible moves which lead to a checkmate? That might take a while, especially if you have a bunch of queens. It is on the exponential scale.
 
Sorry for not being clear. By solutions, I mean all the possible ways I can place the Queens safely. ie. No Queen can attack another Queen on the board.
 
Thanks dduardo.
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 28 ·
Replies
28
Views
6K