N-Queens Recursive Algorithm with Multi-threading

1255 Words3 Pages

Now we place the 3rd queen in the available column. Here again, we don’t have a place to put the fourth queen. So we back track to

the first queen and change its position to the second column as shown in Fig.7 below.

Fig. 7 Placement of three queens

As, shown in the Fig. 8 below, for the 2nd queen we only have one place to put it on the chessboard.

Fig. 8 Placement of first queen with next column after backtracking

After placing the 2nd queen, the available options for next queen are shown below.

Fig. 9 Placement of two queens with different positions

Again, after placing third queen, the available option is as shown in Fig. 10 below.

Fig. 10 Placement of three queens with varying positions

After placing all queens one of the possible solution will look like the diagram shown below.

Fig. 11 One solution of all queens placed

We will repeat all the above steps to find another solution for the 4-queen problem. This whole process is shown in below diagram.

Fig. 12 Complete process tree for 4 queens placement

The data I have gathered is in the form of execution time required to find all possible unique solutions for a given number of queens. I have used two time stamps to find the actual execution time required for this serial algorithm. I have placed one timestamp named as 'start' at the beginning of the function and one timestamp named as 'end' after completion of this function. Then I have calculated the total execution time to find all solutions by simply taking the difference between these two values. I have used the 'Netbeans IDE ' profiler to run the program and collect the data. After collecting this data I have redirected these results to the respective log files. I...

... middle of paper ...

...IEEE IBM Journal of Research and Development Volume 31, July 1987, Issue 4 pg. 464-474

[7] Collins, R. L., Vellore, B., & Carloni, L. P. (2010, March). Recursion-driven parallel code generation for multi-core platforms. In Proceedings of the Conference on Design, Automation and Test in Europe (pp. 190-195). European Design and Automation Association.

[8] Rolfe, T. J. (2008). "A specimen MPI application: N-Queens in parallel" ACM SIGCSE Bulletin, 40(4), 42-45.

[9] Acar, U. A., Charguéraud, A., & Rainey, M. (2013, February). "Scheduling parallel programs by work stealing with private deques" In Proceedings of the 18th ACM SIGPLAN symposium on Principles and practice of parallel programming (pp. 219-228). ACM.

[10]http://scalibq.wordpress.com/2012/06/01/multi-core-and-multi-hreading/#comment-4565

[11]http://theory.cs.uvic.ca/amof/e_queeI.htm#application

Open Document