Nqueens problem, n will be input, output count of all possibles

Click For Summary

Discussion Overview

The discussion revolves around the implementation of the N-Queens problem in programming, specifically focusing on methods to count all possible configurations given an input size n and potentially pre-placed queens on the board. Participants explore different approaches, including brute force and recursive methods, while also considering efficiency and parallelization.

Discussion Character

  • Homework-related
  • Exploratory
  • Technical explanation

Main Points Raised

  • One participant describes a first method involving tabulating possible outcomes and checking their legality, suggesting that existing queens can help narrow down possibilities.
  • The same participant expresses uncertainty about a second method that involves using nested loops for brute force, indicating concerns about efficiency with a high number of loops.
  • Another participant suggests that the problem is suitable for a recursive function, proposing that each recursive call could include a loop that runs in parallel.
  • A request for outlines of a recursive function is made, indicating a desire for guidance on structuring the solution.
  • One participant inquires about the programming language being used, suggesting that language choice may influence the implementation details.

Areas of Agreement / Disagreement

Participants generally agree that a recursive approach may be beneficial, but there is no consensus on the best method to implement the solution or how to effectively parallelize the code. The discussion remains unresolved regarding the optimal approach.

Contextual Notes

Limitations include the potential inefficiency of using a large number of nested loops and the challenge of parallelizing recursive functions, which remains unaddressed in the discussion.

Who May Find This Useful

Readers interested in algorithm design, specifically those tackling combinatorial problems like the N-Queens problem, as well as those looking for insights into parallel programming techniques.

otnaug
Messages
2
Reaction score
0
Hi,

I'm writing a program for nqueens where inputs will be n and possibly a few existing queens already placed on the board. So far I've come up with one method, but got stuck on the second one.
(hoping second method is more efficient)

1st method:
- tabulate possible outcome of (n*n choose n)
- loop through all the outcomes and decide their legality.
- (if there are inputs of existing queens then that's great, i just narrow down from the possible outcome table)

2nd method (stuck):
- i want to do the brute force method on wikipedia -- going horizontal line by line on the board
- for nqueens i need to write n loops.
- so my program will have 20 different sections, 1 for each n up to 20 (with the 20 being a 20-level nested loop), once user input n i'll go to that loop.
- seems like a really bad idea.



any hint is welcome!
the assignment is to further parallelize it, i don't know how to parallelize recursive codes (not to mention i don't know how to write a recursive version of nqueens).



thanks!
 
Physics news on Phys.org
- so my program will have 20 different sections, 1 for each n up to 20 (with the 20 being a 20-level nested loop), once user input n i'll go to that loop.
Looks like an application for a recursive function. Each function has a loop which can run in parallel.
 
mfb said:
Looks like an application for a recursive function. Each function has a loop which can run in parallel.

can you provide some outlines for the recursive function? thanks!
 
FindPosition(LineToFill, board) {
..[/color]//look for possible position for queen
..[/color]//if position possible, call FindPosition(LineToFill+1,modifiedboard)
}

Like that?
 
Which language are you using?
 
Moved to the homework forum. Be mindful of the guidelines for helping with assignments: no complete solutions, etc.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
8
Views
2K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K